Create dialog, generate csv file with the SysOperation Framework (Ax 2012)

As alternative for the Runbase framework, we also can create dialogs with the SysOperation Framework.

In this thread I show how we can create and run the dialog as shown below:

This dialog will generate a csv file which shows us the physical on hand per given date and inventory parameters for the selected item (range). We perform this demo in the USMF entity of the Contoso environment.

Special attention to the query in this dialog, for which is used the AOT query object InventTable. A query gives us enhances options and flexibility in selecting information, for multiple field of the query datasource. Furthermore we see in the dialog the inventory dimension parameters Site (InventSIteId), Warehouse (InventLocationId) and Location (WmsLocationId).  With the transdate parameter to get the physical inventory by any chosen date. 

SysOperational Framework exists of 3 mandatory elements:

1) Data contract class -> Here we define the parameters for the dialog.

2) Service class -> processing of for the business logic, will be called from menu item action.

3) Controller class -> Get the trigger to start the program, via (action) menu item. Links the menu item with the service class.

4) Optional: UI builder class ->  modification of the standard dialog, not used in this example.

Full overview of the project

1. DataContract class (FoxInventOnHandDataContract)

The classDeclaration is decorated with attribute: [DataContractAttribute] all parameter member classes should be decorated with attribute [DataMemberAttribute]

The other attributes SysOperationLabelAttribute, SysOperationHelpTextAttribute and SysOperationDisplayOrderAttribute are optional. Example:

Now I walk through all method of the data contract classClass declaration: 1. Class declaration:

2. Parm methods for the parameter fields:

We also would like to add a query to the dialog. In this example the query is based on the AOT query object “InventTable”

If we open the query in the dialog it looks like this:

We have to add the following 3 methods to the data contract class in order to activate the AOT InventTable query object in our dialog in a correct way. In the method parmQuery we define the query we need in the attribute AifQueryTypeAttribute. This method should be decorated with the attributes as shown below. The methods setQuery and getQuery is used to decode and encode the packedQuery. Actually what happens here is that our query will be converted to a Base64 type. Base 64 gives you the opportunity to encode your query to binary data as a string and decode it back as a query object.

2. Data Service class (FoxInventOnHandDataService)

Processing the logic, in our example we are generating the csv file or calculating the physical inventory for the item’s given dimensions. In this example it is possible to call the logic in this class directly from menu item, and so skip the controller class. We can call the main method of this class, which is in our example method process directly from menu item if we configure the menu item as following,but is is recommendable to use controller class instead.

Another point: we can link the Data service class to a service object. See example in the screenshot below:

Here we can see how the AOT Service object is linked to the data service class:

If we add operation, we see that we can use the operation process, which is actual the main method of the data service class. When we add the process as an operation, we can run it as an (AIF) service.

In the service class (FoxInventOnHandDataService) we have the following methods:

method generateFile, which generates a csv file with file name based on current date and time:

method getInventOnHand(ItemId _itemId) whch calculates the physical stock for an item/dimesion combination for any date.

method process, this method has the contract as parameter. In order to get contract info into the class we have to decorate the class with the attribute [SysEntryPointAttribute]. Watch also the initialization of the queryRun. We use the getQuery() method from the contract in order to get the query run from the InventTable query object:

3. Controller class (FoxInventOnHandController), as this class contains main method, we can link menuitem (action) to it. We extend this class with SysOperationServiceController. In this example we use the methods new , which connect the controller class and the main method.

In order to link a menu item to the controller class, the following parameter setup should be configured on the menu item properties ObjectType and Object. When we run the menu item, the main method of the controller class will be invoked which triggers the activation of the dialog.

When we run the dialog a csv file is generated in the given filepath:

When we check the invent on-hand in Dynamics Ax for example M0001 we see that’s exactlt the same as in the csv file:

If we select a date far in the past for example 01/01/2000, then we see that there is no stock yet, which is correct too.