Export (0) Print
Expand All

Walkthrough: Creating a Workflow Template

Dynamics AX 2009

In Microsoft Dynamics AX, you define a workflow by creating a template to base the workflow on. In this walkthrough, you will create a workflow template in the Application Object Tree (AOT) that you can add approvals and tasks to.

A workflow template defines information about:

  • Which workflow document to use. The workflow document exposes calculated fields and identifies the query that exposes data fields for the workflow.

  • Tasks and approvals that can be configured by the end user.

  • Workflow categories used for assigning a workflow template to a specific module.

  • Menu items and event handlers.

This walkthrough illustrates the following tasks:

  • Create a workflow template in the AOT.

  • Create a query to expose data for conditions.

  • Create a workflow document class to identify the query and calculated fields.

  • Bind the query to the workflow document class.

  • Bind the workflow document class to the workflow template.

  • Create a workflow category.

  • Bind the workflow category to the workflow template.

  • Create a SubmitToWorkflow menu item.

  • Bind the workflow menu item to the workflow template.

  • Set a license configuration key for the workflow template.

To complete this walkthrough, you will need:

  • Microsoft Dynamics AX

  • A license file that has access to the MorphX development environment

To create a workflow template in the AOT

  1. In the AOT, expand the Workflow node.

  2. Right-click the Workflow Templates node, and then select New Workflow Template. A workflow template group displays under the Workflow Template node.

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

  4. In the Properties sheet, set the Name property to MyWorkflowTemplate.

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

After the workflow template is created, you can create the objects that you need to bind to the workflow template. For this walkthrough, the next step is to create a query to identify the table data fields used for the workflow document.

To create a query for a workflow

  1. In the AOT, right-click the Queries node, and then select New Query. A query group displays under the Queries node.

  2. Right-click the new query, click Rename, and then enter MyQuery.

  3. Expand the new query, right-click the Data Sources node, and then click New Data Source. A data source group displays under the Data Sources node.

  4. Right-click the new data source group and then click Properties.

  5. In the Properties sheet, set the Table property to CustTable.

    NoteNote

    By default, all data fields in the CustTable table are exposed for workflow conditions. To remove data fields, set the Dynamic property on the Fields node of the data source to No. Expand the Fields node, right-click a field, and then click Delete. If the query is not saved, the Delete command is not available.


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

After a Microsoft Dynamics AX query is created, you must create a workflow document class that identifies the query name, and then bind it to the workflow template.

To create a workflow document class

  1. In the AOT, right-click the Classes node, and then select New Class. A class group displays under the Classes node.

  2. Right-click the new class, click Rename, and then enter MyWorkflowDocumentClass.

  3. Expand MyWorkflowDocumentClass, right-click classDeclaration, and then click Edit. The Class Editor window opens.

  4. In the Class Editor window, enter the following code in the class declaration.

    public class MyWorkflowDocumentClass extends WorkflowDocument
    {
    }
    
  5. Close the Class Editor window and click Yes to save changes.

  6. Right-click MyWorkflowDocumentClass, point to Override Method, and then click getQueryName. A method node named getQueryName displays under the workflow document class node and the Class 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 the WorkflowDocument.getQueryName Method.


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

    QueryName getQueryName()
    {
        return querystr(MyQuery);
    }
    
  8. Close the Class Editor window and click Yes to save changes.

The workflow class that you just created does not contain calculated fields. If your application requires a calculated field, you should add that to this class. For more information, see How to: Create a Workflow Document Class. After you create the workflow document class, you must bind it to the workflow template.

To bind a workflow document class to a workflow template

  1. In the AOT, expand the Workflow Templates node, right-click the workflow template named MyWorkflowTemplate, and then click Properties.

  2. In the Properties sheet, set the Document property to MyWorkflowDocumentClass.

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

After a workflow document is bound to a workflow template, you can make the workflow template available in a specific module by using workflow categories. In this walkthrough, you will create a workflow category.

To create a workflow category

  1. In the AOT, right-click the Workflow Categories node, and then select New Workflow Category. A new workflow category group displays under the Workflow Categories node.

  2. Right-click the new workflow category and then click Properties.

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

    Property

    Value

    Name

    MyWorkflowCategory

    Module

    Customer

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

After a workflow category is created, you can bind it to the workflow template.

To bind a workflow category to a workflow template

  1. In the AOT, right-click MyWorkflowTemplate, and then select Properties.

  2. In the Properties sheet, set the Category property to MyWorkflowCategory.

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

Now that the workflow template has a workflow document and category, you can create event handlers for events such as workflow started, configuration data change, completed, and canceled events. However, to simplify this walkthrough, you will not create any event handlers. For more information about how to create and use workflow events in an application, see Handling Workflow Events.

To enable end users to submit a workflow document for approval, you will have to create an action menu item that will display in the workflow menu bar. When the user clicks Submit, the SubmitToWorkflow class that is bound to the action menu item will run. This class can perform tasks for an application, such as activating the workflow, changing workflow states, and updating the user interface. For more information, see Activating a Workflow.

In this walkthrough, you will create a class that displays a message in the user interface, and then bind that class to the MySubmitToWorkflow action menu item property.

To create a SubmitToWorkflow class

  1. In the AOT, right-click the Classes node, and then select New Class. A class group displays under the Classes node.

  2. Right-click the new class, click Rename, and then enter MySubmitToWorkflowClass.

  3. Right-click MySubmitToWorkflowClass, and then click New Method. The Class Editor window opens.

  4. In the Class Editor window, insert the following code.

    public static void main(Args args)
    {
        // Variable declaration.
        recId _recId = args.record().RecId;
        WorkflowCorrelationId _workflowCorrelationId;
        // Hardcoded template name
        WorkflowTemplateName _workflowTemplateName = workflowtemplatestr("MyWorkflowTemplate");
        // Initial note is the information that users enter when they
        // submit the document for workflow.
        WorkflowComment _initialNote = "";
        WorkflowSubmitDialog workflowSubmitDialog;
        ;
    
        // Opens the submit to workflow dialog.
        workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
        workflowSubmitDialog.run();
    
        if (workflowSubmitDialog.parmIsClosedOK())
        {
               _recId = args.record().RecId;
            // Get comments from the submit to workflow dialog.
            _initialNote = workflowSubmitDialog.parmWorkflowComment();
    
            try
            {
                ttsbegin;
    
                // Activate the workflow.
                _workflowCorrelationId = Workflow::activateFromWorkflowTemplate(_workflowTemplateName, _recId, _initialNote, NoYes::No);
    
                // Send an Infolog message.
                info("Submitted to workflow.");
    
                ttscommit;
            }
    
            catch(exception::Error)
            {
                info("Error on workflow activation.");
            }
        }
    }
    
  5. Close the Class Editor window and click Yes to save changes.

After MySubmitToWorkflowClass is created, you can create an action menu item to bind this class to.

To create an action menu item and bind it to the workflow template

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

  2. Right-click the Action node, and then click New Menu Item. An action menu item displays under the Menu Items node.

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

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

    Property

    Value

    Name

    MySubmitToWorkflowActionMenuItem

    Label

    Submit

    ObjectType

    Set to Class. Use this value to implement the class for this action item.

    Object

    Set to MySubmitToWorkflowClass.

    SecurityKey

    CustMisc

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

  6. In Workflow node, right-click MyWorkflowTemplate, and then click Properties.

  7. In the Properties sheet, set the SubmitToWorkflowMenuItem property to MySubmitToWorkflowActionMenuItem.

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

You have now created a workflow template based on the customer table. To use the customer table form for a workflow, you must enable the form for workflow and then create a workflow configuration. For more information, see Walkthrough: Adding Workflow to an Existing Form.

Community Additions

ADD
Show:
© 2014 Microsoft