Create a workflow document class

Important

Customers using Human Resources, the functionality noted in this article is currently available in both the stand-alone Dynamics 365 Human Resources and the merged Finance infrastructure. Navigation might be different than noted while we make updates. If you need to find a specific page, you can use Search.

You define table fields in a query to create workflow conditions. In a typical scenario, calculated fields are used 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. 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 will be accessed. For more information about workflow queries, see Create a query for a workflow type.

Note

If you used the Workflow wizard to create the workflow type, the wizard has already created the workflow document class.

Create a workflow document class

  1. 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.
  2. Expand the new class, select classDeclaration, right-click the class declaration, and then select Edit.

  3. Enter the following code in the class declaration.

    class <MyWorkflowDocumentClassName> extends WorkflowDocument
    {
    }
    
  4. Close the Editor window, and select Yes to save your changes.

  5. 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.

  6. 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:

  • It must be named parm <name>.
  • It must define the CompanyId, TableId, and RecId parameters.
  • It must return an extended data type (EDT) that will be 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

  1. In the workflow document class that you want to add a calculated field to, right-click the class, and then select New Method. A new method node appears under the Classes node.

  2. Right-click the new method node, and then select Edit.

  3. Enter code in the format that is 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;
    }
    

See also

Associate a workflow document class with a workflow type