Walkthrough: Creating a Workflow with a Task and an Approval

In Microsoft Dynamics AX, you can add tasks and approvals to a workflow in the Application Object Tree (AOT). In this walkthrough, you will create and add a task and an approval to the MyWorkflowTemplate based on the CustTable form. This walkthrough builds on the Walkthrough: Creating a Workflow Template and the Walkthrough: Adding Workflow to an Existing Form.

This walkthrough illustrates the following tasks:

  • Create a display menu item used by both the task and the approval.

  • Create a task.

  • Create a task action menu item.

  • Create a task outcome.

  • Create an approval.

  • Create an approval action menu item.

  • Define an approval outcome.

  • Bind a task and approval to a workflow template.

  • Create a workflow configuration.

Prerequisites

To complete this walkthrough, you will need:

To create a display menu item

  1. In the AOT, expand the Menu Items node.

  2. Right-click the Display node, and then click New Menu Item. A new menu item group displays under the Display node.

  3. Right-click the new menu item and then click Properties.

  4. In the Properties sheet, set the following properties.

    Property

    Value

    Name

    MyWorkflowDisplayMenuItem

    ObjectType

    Form

    Object

    CustTable

    SecurityKey

    CustMisc

  5. In the AOT, right-click MyWorkflowDisplayMenuItem, and then click Save.

This display menu item identifies the workflow document form to display when you select it in the Unified Worklist in the client. For example, the Customer Table form opens when you click the Go To Customer Table button in the Unified Worklist.

To create a task

  1. In the AOT, expand the Workflow node.

  2. Right-click the Tasks node and then select New Task. A new workflow task group displays under the Tasks node.

  3. Right-click the new workflow task and then click Properties.

  4. In the Properties sheet, set the following properties.

    Property

    Value

    Name

    MyWorkflowTask

    Document

    MyWorkflowDocument

    NoteNote
    This value is available only if you complete Walkthrough: Creating a Workflow Template.

    ParticipantProvider

    WorkflowUserGroupParticipantProvider

    NoteNote
    This value is the default participant provider used to resolve a user group or role into one or more specific user IDs. For more information, see Workflow Providers Overview.

    DueDateProvider

    WorkflowWorkCalendarDueDateProvider

    NoteNote
    This value is the default due date provider used to determine the due date for a task or approval, or the due date for a step in a task or approval. For more information, see Workflow Providers Overview.

    DocumentMenuItem

    MyWorkflowDisplayMenuItem

  5. In the AOT, right-click MyWorkflowTask, and then click Save.

The next steps are to add a custom outcome and an Action menu item to the task. Each task must have at least one outcome of type Complete. Each outcome must have an action menu item to display the work item button in the user interface.

To create a task action menu item

  1. In the AOT, expand the Menu Items node.

  2. Right-click the Action node, and then click New Menu Item. A new menu item group displays under the Action node.

  3. Right-click the new menu item and then click Properties.

  4. In the Properties sheet, set the following properties.

    Property

    Value

    Name

    MyWorkflowActionMenuItemComplete

    Label

    Complete

    ObjectType

    Class

    Object

    WorkflowWorkItemActionManager

    NoteNote
    You can use this class to process work item action types such as Return, RequestChange, Complete, Deny, and Delegate. You will need to create a custom class for Submit and ReSubmit as these action types require changes to the document status. For more information, see WorkflowWorkItemActionManager Class.

    SecurityKey

    CustMisc

  5. In the AOT, right-click MyWorkflowActionMenuItemComplete, and then click Save.

To create a task outcome

  1. In the AOT, expand MyWorkflowTask, right-click Outcomes, and then click New Outcome. A new workflow task outcome group displays under the Outcomes node.

  2. Right-click the new outcome and then click Properties.

  3. In the Properties sheet, set the following properties.

    Property

    Value

    Name

    MyTaskOutcomeComplete

    Type

    Complete

    Enabled

    Yes

    ActionMenuItem

    MyWorkflowActionMenuItemComplete

  4. In the AOT, right-click MyWorkflowTask, and then click Save.

After a workflow task with an outcome is created, you can add the workflow task to the Required Elements node of a workflow template. If the task is not required or a specific sequence is not needed, you can add the task to a workflow configuration in the configuration user interface. For more information, see Creating Tasks and Approvals.

To add a required task to a workflow template

  1. Expand the Workflow Templates node, and then expand the MyWorkflowTemplate node.

  2. Expand the Tasks node, and then drag the MyWorkflowTask node onto the Required Elements node in the MyWorkflowTemplate node.

    Note

    The Document property setting of the workflow task and the workflow template must be identical.


  3. In the AOT, right-click MyWorkflowTemplate, and then click Save.

Next, you will create a workflow approval with two outcomes and then add it to the workflow template.

To create an approval

  1. Right-click the Approvals node and then select New Approval. A new workflow approval group displays under the Approvals node.

  2. Right-click the new approval and then click Properties.

  3. In the Properties sheet, set the following properties.

    Property

    Value

    Name

    MyWorkflowApproval

    Document

    MyWorkflowDocument

    NoteNote
    This value is available only if you complete Walkthrough: Creating a Workflow Template.

    ParticipantProvider

    WorkflowUserGroupParticipantProvider

    NoteNote
    This value is the default participant provider used to resolve a user group or role into one or more specific user IDs. For more information, see Workflow Providers Overview.

    DueDateProvider

    WorkflowWorkCalendarDueDateProvider

    NoteNote
    This value is the default due date provider used to determine the due date for a task or approval, or the due date for a step in a task or approval. For more information, see Workflow Providers Overview.

    DocumentMenuItem

    MyWorkflowDisplayMenuItem

  4. In the AOT, right-click MyWorkflowApproval, and then click Save.

You can expand the Outcomes node and enable or disable outcomes and add event handlers. However, to simplify this walkthrough, only the Approve and Deny outcomes are enabled.

To create an approval action menu item

  1. In the AOT, expand the Menu Items node.

  2. Right-click the Action node, and then click New Menu Item. A new menu item group displays under the Action node.

  3. Right-click the new menu item and then click Properties.

  4. In the Properties sheet, set the following properties.

    Property

    Value

    Name

    MyWorkflowActionMenuItemApprove

    Label

    Approve

    ObjectType

    Class

    Object

    WorkflowWorkItemActionManager

    Note   You can use this class to process work item action types such as Return, RequestChange, Complete, Deny, and Delegate. This approval action item is processed using type Complete. You will need to create a custom class for Submit and ReSubmit as these action types require changes to the document status. For more information, see WorkflowWorkItemActionManager Class.

    SecurityKey

    CustMisc

  5. In the AOT, right-click MyWorkflowActionMenuItemApprove, and then click Save.

  6. Right-click the Action node, and then click New Menu Item. A new menu item group displays under the Action node.

  7. Right-click the new menu item and then click Properties.

  8. In the Properties sheet, set the following properties.

    Property

    Value

    Name

    MyWorkflowActionMenuItemDeny

    Label

    Deny

    ObjectType

    Class

    Object

    WorkflowWorkItemActionManager

    NoteNote
    You can use this class to process work item action types such as Return, RequestChange, Complete, Deny, and Delegate. You will need to create a custom class for Submit and ReSubmit as these action types require changes to the document status. For more information, see WorkflowWorkItemActionManager Class.

    SecurityKey

    CustMisc

  9. In the AOT, right-click MyWorkflowActionMenuItemDeny, and then click Save.

To define an approval outcome

  1. Expand MyWorkflowApproval, and then expand Outcomes. Right-click the Approve outcome and then click Properties.

  2. In the Properties sheet, set the following properties.

    Property

    Value

    Enabled

    Yes

    ActionMenuItem

    MyWorkflowActionMenuItemApprove

  3. In the Outcomes node, right-click the Deny outcome, and then click Properties.

  4. In the Properties sheet, set the following properties.

    Property

    Value

    Enabled

    Yes

    ActionMenuItem

    MyWorkflowActionMenuItemDeny

  5. In the Outcomes node, set the Enabled property for RequestChange and Reject to No. By setting this property to No, the action buttons in the user interface for Request Change and Return are unavailable.

  6. In the AOT, right-click MyWorkflowApproval, and then click Save.

After a workflow approval with outcomes is created, you can add the approval to the Required Elements node of a workflow template. For more information, see Creating Tasks and Approvals.

To add a required approval to a workflow template

  1. Expand the Workflow Templates node, and then expand the MyWorkflowTemplate node.

  2. Expand the Approvals node, and then drag the MyWorkflowApproval node onto the Required Elements node of the MyWorkflowTemplate node.

    Note

    The Document property setting of the workflow task and the workflow template must be identical.


  3. In the AOT, right-click MyWorkflowTemplate, and then click Save.

To view the approval and the task in the configuration user interface, you must create a new configuration.

Note

To update metadata changes in the client, you must close and restart Microsoft Dynamics AX before continuing.


To create a configuration

  1. On the Setup pane in the Accounts receivable module, click Workflow configurations. The Workflow configuration form is displayed.

  2. In the Workflow configuration form, click New. The Create configuration: Select a template form is displayed.

  3. On the Create configuration: Select a template form, select MyWorkflowTemplate, and then click Create configuration. The Workflow: MyWorkflowTemplate form is displayed.

  4. In the Workflow: MyWorkflowTemplate form, click the General tab, and then click Create instruction. The Edit message form is displayed.

  5. In the Message text box on the Edit message form, enter My workflow submit instructions., and then click OK.

  6. Click the Details tab, and then select MyWorkflowTask in the Workflow elements list. The Task details tabs are displayed.

  7. Click Create subject. The Edit message form is displayed.

  8. On the Edit message form, in the Message text box, enter My subject., and then click OK.

  9. On the Overview tab, click Create instruction. The Edit message form is displayed.

  10. On the Edit message form, in the Message text box, enter My workflow instructions., and then click OK.

  11. In the Workflow elements list, expand MyWorkflowApproval, and then select Step 1. The Step details tabs are displayed.

  12. Click the Overview tab for Step details, and then repeat steps 7 - 10.

  13. Close the Workflow: MyWorkflowTemplate form.

  14. In the Workflow configuration form, click the General tab, and then click Set as active to activate this workflow template configuration.

  15. On the Overview tab, select the MyWorkflowTemplate configuration, and then click Set as default to use this workflow configuration as the default workflow configuration.

  16. Close the Workflow configuration form.

  17. On the Common Forms menu in the Accounts receivable module, click Customer Details to display the form.

  18. The workflow toolbar is displayed at the top of the CustTable form.

    Note

    Since the canSubmitToWorkflow method on the CustTable form always returns true, the workflow toolbar and the Submit button are always displayed. You can test the remaining sections of this workflow after the workflow is submitted and processed by changing the canSubmitToWorkflow method to always return false.


Next Steps

You must create a state model to identify and persist the state of the workflow and work items in the database. For more information, see Requirements for Enabling Workflow in an Application Module.

You can simulate server data flow for the workflow process by using the Tutorial_WorkflowProcessor form located in the Forms node in the AOT.

You can expand this walkthrough by adding additional tasks and subworkflows. Subworkflows are workflows that run inside another workflow. For more information, see "Configure a Subworkflow" in the Applications and Business Processes Help.

See Also

Walkthrough: Creating a Workflow Template

Walkthrough: Adding Workflow to an Existing Form

Requirements for Enabling Workflow in an Application Module

Creating Tasks and Approvals