Walkthrough: Adding Workflow to an Existing Form

Dynamics AX 2009

In Microsoft Dynamics AX, you can add workflow to new or existing forms. In this walkthrough, you will add workflow to the CustTable form, create a method to run when the form is submitted to workflow, and then create a configuration to test the workflow.

To add workflow to a form, you must have a workflow template and a document class that identifies the data fields that the workflow uses. This walkthrough builds on the Walkthrough: Creating a Workflow Template.

This walkthrough illustrates the following tasks:

  • Enable the CustTable form for workflow.

  • Create a canSubmitToWorkflow method on the CustTable form.

  • Create a configuration.

To complete this walkthrough, you will need:

To enable a form for workflow

  1. In the Application Object Tree (AOT), expand the Forms node.

  2. Expand the CustTable form, and then expand the Designs node.

  3. In the Designs node, right-click the Design child node, and then click Properties.

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

    Property

    Value

    WorkflowEnabled

    Yes

    WorkflowDataSource

    CustTable

    NoteNote
    This is the root data source specified in the query used for the Document property on the MyWorkflowTemplate template. For more information, see Walkthrough: Creating a Workflow Template.
  5. In the AOT, right-click the CustTable form, and then click Save.

After the form is enabled for workflow, you must add a canSubmitToWorkflow method to the form. This method runs before the Submit button is enabled to verify that the workflow document is in a valid state to submit to workflow. When this method returns true, the Submit button is enabled.

NoteNote

If there are no records in the data source and the canSubmitToWorkflow method returns true, an exception is thrown. Therefore, you should programatically check for a record when you evaluate the state of the workflow.


To create a canSubmitToWorkflow method on a form

  1. In the AOT, expand the CustTable form, right-click the Method node, point to Override Method, and then click canSubmitToWorkflow.

  2. A method node named canSubmitToWorkflow displays under the Methods node and the Class Editor window opens.

  3. In the Class Editor window, enter the following code to enable the Submit button on the form for workflow.

    public boolean canSubmitToWorkflow()
    {
        // ToDo This method always returns true and the Submit
        // button will always be displayed on the form. Enter code
        // here to only return true when the document is NotSubmitted.
        // Also, add code to check if a record exists in the data source.
        return true;
    }
    
  4. Close the Class Editor window and click Yes to save changes.

Now that the form is enabled for workflow, you must create a workflow configuration to display the Submit button on the workflow toolbar.

NoteNote

Before creating the first workflow configuration, a number sequence must be assigned in the Basic module Settings for workflow menu item on the Setup menu. For more information, open the Settings for workflow form and press F1.


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. Close the Workflow: MyWorkflowTemplate form.

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

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

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

  10. The workflow toolbar is displayed at the top of the CustTable form. Click the View Workflow Instructions icon on the workflow toolbar to display the submission instructions that you created in step 5. Click Submit to see the submitted to workflow Infolog message.

After you complete Walkthrough: Creating a Workflow Template and Walkthrough: Adding Workflow to an Existing Form, you have the foundation for a basic workflow. Now you can add tasks and approvals to the workflow. For more information, see Walkthrough: Creating a Workflow with a Task and an Approval.

Community Additions

ADD
Show: