Microsoft Dynamics AX table fields are defined in a query to create workflow conditions. A limitation of a Microsoft Dynamics AX query is that you cannot define calculated fields in the query itself. It is a common scenario to use calculated fields to determine the behavior of a workflow. For example, a dynamic sales total of all records in a table can be used as a workflow condition to determine whether the step should be used. To overcome this query limitation, you must use a workflow document class.
The workflow document class that you create defines table fields for conditions in two ways: the Application Object Tree (AOT) query and parameter methods. The getQueryName method of the WorkflowDocument Class must be overridden to return the name of the query. You can optionally add calculated fields by adding parameter methods with a specific signature on the class.
Before you begin these procedures, you must create a query that specifies the data that will be accessed.
The following procedures show how to create a workflow document class including a parameter method for a calculated field.
If you used the Workflow Wizard to create the workflow type, the workflow document class will have already been created by the wizard.
To create a workflow document class
In the AOT, expand the Classes node.
Right-click the Classes node, and then select New Class. A class group displays under the Classes node.
Right-click the new class, click Rename, and then enter a name for the workflow document class.
Expand the new class, select classDeclaration, right-click the class declaration, and then click Edit.
Enter the following code in the class declaration.
class <MyWorkflowDocumentClassName> extends WorkflowDocument
Close the Editor window and click Yes to save changes.
Right-click the new class, point to Override Method, and then click getQueryName. A method node named getQueryName displays under the workflow document class node and the Editor window opens.
Be sure to select getQueryName as the method to override. The WorkflowDocument.getQuery Method is used only internally to retrieve the actual query based on the string returned by theWorkflowDocument.getQueryName Method.
In the Editor window, enter the following code for the query method.
After you create the workflow document class, you can bind it to the workflow type. For more information, see How to: Associate a Workflow Document Class with a Workflow Type.
To add a calculated field to the workflow document class, it must:
Be named parm <name>.
Define the parameters CompanyId, TableId, and RecId.
Return an extended data type that will be included in the list of fields for defining conditions or notification messages. The label for the EDT must uniquely identify the value.
To add a calculated field to the workflow document class
In the workflow document class that you want to add a calculated field to, right-click the class, and then click New Method. A new method node displays under the Classes node.
Right-click the new method node, and then click Edit. Enter code that uses the format shown in the following code example.
The following code example shows how to add a calculated field to determine the total credit amount for a journal.
public TotalJournalCreditAmount parmTotalJournalCreditAmount(CompanyId _companyId, TableId _tableId, RecId _recId)
// The calculateAmounts method contains business and validation logic
this.calculateAmounts(_companyId, _tableId, _recId);