How to: Create a Workflow Task AX 2012

A Microsoft Dynamics AX workflow task is a single unit of work that must be performed. A workflow may contain one or more tasks.

The following procedure describes how to create a new workflow task in the AOT.

To create a workflow task

  1. In the AOT, expand the Workflow node.
  2. Right-click the Tasks node, and then click Add-Ins > Task wizard. The Workflow wizard is displayed. This wizard will help you create a new workflow task.
  3. Click Next.
  4. Set the following values for the wizard.

Value

Description

Name

The name that will be used for the workflow task.

Workflow document

The class that defines the workflow document for which you are creating a task.

clip_image001Note

This setting must match the Document property setting used in the workflow type for the task.

Document preview field group

The initial set of fields displayed in the unified work list. Select a field group from the root table specified in the Workflow document that you selected. The Workflow document value must be set before you can select a field group.

Document menu item

Choose the menu item that points to the main form that displays the document for which you are creating a workflow task.

Document web menu item

Choose the web menu item that points to the Enterprise Portal page that displays the document for which you are creating a workflow task.

  1. Specify which types of menu items you want to create. You can create menu items for the Microsoft Dynamics AX client, web menu items for Enterprise Portal, or items for both.
  2. Click Next.
  3. Define the task outcomes. For each outcome that you want to support, supply a Name for the outcome. The name cannot contain spaces. Specify the Type for the outcome. Choose one of the following types:
    • Complete - Completes the workflow task and continues the workflow forward.
    • Return - Returns the task to the originator for changes and then resubmission back to workflow.
    • RequestChange - Sends the task to a specified user for changes and then resubmission back to workflow.
    • Deny - Completes the task as denied and continues the workflow forward.

Click Add.

Note

Each task must have one outcome of type Complete.

  1. After you have finished defining the outcomes, click Next. A list of all of the resources that will be created for the workflow task is displayed.
  2. Click Finish to create the resources. The wizard will create classes, menu items, web menu items, the task, and a project that contains all of the items.
  3. A dialog box will be displayed that indicates the status. Click OK. The project that contains the workflow type resources is displayed.

After a workflow task is created, you can add the workflow task to the Supported Elements node of a workflow type.

How to: Create a Workflow Document Class [AX 2012]

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.

NoteNote

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
  1. In the AOT, expand the Classes node.

  2. Right-click the Classes node, and then select New Class. A class group displays under the Classes node.

  3. Right-click the new class, click Rename, and then enter a name for the workflow document class.

  4. Expand the new class, select classDeclaration, right-click the class declaration, and then click Edit.

  5. Enter the following code in the class declaration.

    X++

    class <MyWorkflowDocumentClassName> extends WorkflowDocument
    {
    }


  6. Close the Editor window and click Yes to save changes.



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

    NoteNote

    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.



  8. In the Editor window, enter the following code for the query method.

    X++

    QueryName getQueryName()
    {
    return querystr(<MyWorkflowDocumentQueryName>);
    }

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



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



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

X++

public TotalJournalCreditAmount parmTotalJournalCreditAmount(CompanyId _companyId, TableId _tableId, RecId _recId)
{
// The calculateAmounts method contains business and validation logic
this.calculateAmounts(_companyId, _tableId, _recId);

return totalJournalCreditAmount;
}