Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You define table fields in a query to create workflow conditions. In a typical scenario, you use calculated fields to determine the behavior of a workflow. For example, you can use a dynamic sales total of all records in a table as a workflow condition to determine whether the step should be used. However, a limitation of queries is that you can't define calculated fields in the queries themselves. To overcome this query limitation, you must use a workflow document class. This article describes how to create a workflow document class.
The workflow document class that you create defines table fields for conditions in two ways: the Application Explorer query and parameter methods. You must override the getQueryName method of the WorkflowDocument class to return the name of the query. You can optionally add calculated fields by adding parameter methods that have a specific signature on the class. For more information about workflow conditions, see Configure workflow properties and Configure conditional decisions in a workflow.
The following procedures explain how to create a workflow document class that includes a parameter method for a calculated field. Before you begin, you must create a query that specifies the data that the workflow accesses. For more information about workflow queries, see Create a query for a workflow type.
Note
If you use the Workflow wizard to create the workflow type, the wizard already creates the workflow document class.
Create a workflow document class
Follow one of these steps to create a new query:
- In Application Explorer, expand the Classes node. Right-click the Classes node, and then select New Class. A class group appears under the Classes node. Right-click the new class, select Rename, and then enter a name for the workflow document class.
- On the Project menu, select Add new item. In the Add new item dialog box, select Class. Enter a name for the class, and then select Create.
Expand the new class, select classDeclaration, right-click the class declaration, and then select Edit.
Enter the following code in the class declaration.
class <MyWorkflowDocumentClassName> extends WorkflowDocument { }Close the Editor window, and select Yes to save your changes.
Right-click the new class, point to Override Method, and then select getQueryName. A method node that is named getQueryName appears under the workflow document class node, and the Editor window appears.
Note
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 that is returned by the WorkflowDocument.getQueryName method.
In the Editor window, enter the following code for the query method.
QueryName getQueryName() { return querystr(<MyWorkflowDocumentQueryName>); }
After you create the workflow document class, you can bind it to the workflow type. For more information, see Associate a workflow document class with a workflow type.
You can add a calculated field to the workflow document class only if it meets these conditions:
- You name it parm <name>.
- It defines the CompanyId, TableId, and RecId parameters.
- It returns an extended data type (EDT) that's included in the list of fields that define conditions or notification messages. The label for the EDT must uniquely identify the value.
Add a calculated field to the workflow document class
In the workflow document class where you want to add a calculated field, right-click the class, and then select New Method. A new method node appears under the Classes node.
Right-click the new method node, and then select Edit.
Enter code in the format shown in the following example. This 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); return totalJournalCreditAmount; }