How to create a Runnable class in Dynamics 365 Function and operation.

In this blog, we will see how to create a runnable class and how to execute them.

In X++, a runnable class is a class that can be executed directly from the Application Object Tree (AOT) in Microsoft Dynamics AX. A runnable class is a class that has a static main method, which is the entry point of the program. The main method is where you write the code that you want to execute when the class is running.

Here’s an example of a simple runnable class in X++: S

To run this class, you need to navigate to the AOT and find the class in the Classes node. Right-click the class and select “Open” to open the class in the code editor. Then, right-click the class and select “Compile” to compile the class. Finally, right-click the class and select “Run” to run the class. The output of the class should be displayed in the Infolog.

In this example, the main method uses the info function to display the message “Hello World!” in the Infolog. The info function is a handy function for displaying messages in the Infolog during development and testing.

You can also pass parameters to a runnable class. To do this, you need to modify the main method to accept an Args object, which contains the parameters passed to the class. Here’s an example of a runnable class that accepts a single string parameter:

In this example, the main method uses the length method of the Args object to check if any parameters have been passed to the class. If parameters have been passed, the get method of the Args object is used to retrieve the first parameter and assign it to the message variable.

Before creating a new method always gives a Summary and parameters list before the method in the following manner.

The summary is a brief about the method written below. And the parameters list is to know about the number and type of parameters given to the method.

For using the tables and form or EDTs in the runnable class we need to declare a variable in the class itself. For example, we have a table called AA_Students. To use it in the select query we need to declare it before using it.

Now, the student variable is the AA_student table’s variable which can be used to access the table fields in the runnable class.

While select is a loop that will run until all the records are traversed based on the conditions given in the select query. And all the code written inside the curly brackets is executed for each row the select query returns.

The Count aggregate function will only work with the integer field.

Joining tables in the select query is easy and we use the ‘join’ keyword the same as the ‘inner join’ in SQL. And there are other joins like outer join, exists join, non exists joins.

We use “==” for equal to and “&&” to represent the “AND” in the query.

Strfmt is the function used to format a string with the given results.

The string will contain the table data like the college name and number of students.

After executing the runnable class, we get the output in the Infolog.

Afroz Labbai 

D365 Business Central

Addend Analytics

Addend Analytics is a Microsoft Gold Partner based in Mumbai, India, and a branch office in the U.S.

Addend has successfully implemented 100+ Microsoft Power BI and Business Central projects for 100+ clients across sectors like Financial Services, Banking, Insurance, Retail, Sales, Manufacturing, Real estate, Logistics, and Healthcare in countries like the US, Europe, Switzerland, and Australia.

Get a free consultation now by emailing us or contacting us.