Export (0) Print
Expand All

How to: Activate a Workflow using the Sequence Number

Dynamics AX 2009

In Microsoft Dynamics AX, workflow can be activated by using a workflow template, configuration ID, or sequence number. When you activate a workflow by using the sequence number, the specified workflow configuration version is used to create a new workflow instance. You should activate a workflow using this procedure when there is more than one configuration for the same workflow template and you want to run the active configuration version. These procedures describe how to use a configuration sequence number to activate a workflow.

To activate a workflow by using a workflow configuration sequence number, follow these steps:

  1. Create an action menu item.

  2. Bind the action menu item to the workflow template.

  3. Create and implement a class to activate the workflow.

  4. Associate the action menu item with the class.

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

    The name that is used to reference the menu item action, for example, SubmitToWorkflow.

    Label

    The label used for the action menu item in the user interface. For example, enter Activate to identify a button that will activate the workflow.

    ObjectType

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

    SecurityKey

    Set to enable which users have permissions to use this functionality.

  5. In the AOT, expand the Workflow node, and then expand the Workflow Templates node.

  6. Right-click the workflow template that you want to bind an action menu item to and then click Properties.

  7. In the Properties sheet, set the SubmitToWorkflowMenuItem property to the action menu item that you created.

After an action menu item is created, the next step is to create a class that implements the action menu item.

To create a class to activate a workflow using a configuration sequence number

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

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

  3. Right-click the new class and then click New Method. The Class Editor window opens.

  4. In the Class Editor window, insert the code for the action to take to activate the workflow by using a configuration sequence number.

    NoteNote

    See the code example in the following example that contains a static main method implementation for an issue handling workflow.


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

  6. Expand the Action node, and then select the action menu item to implement the class created in the previous procedure.

  7. In the Properties sheet, set the Object property to the name of the class to activate the workflow.

The following code example shows a sample implementation of the static main method on class that activates a workflow by using a specified sequence number. For more information, see Workflow::activateFromWorkflowSequenceNumber Method. In this example, the workflow configuration is used to enable the issue handling workflow in a module.

This code example uses the IssueStateChangeManager class to change the state of the business document as the workflow progresses. You can also manage the state change that results from workflow activation directly in the SubmitToWorkflow class that you create for the SubmitToWorkflowMenuItem property setting in the workflow template.

When the workflow is activated, the following code will open a dialog box to add user comments.

public static void main(Args args)
{
    // Variable declaration.
    recId _recId = args.record().RecId;
    WorkflowCorrelationId _workflowCorrelationId;
    WorkflowSequenceNumber _workflowSequenceNumber = wfConfig.SequenceNumber;
    // 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;
 
            wfConfig =_args.caller().getActiveWorkflowConfiguration();

            // Activate the workflow.
            _workflowCorrelationId = Workflow::activateFromSequenceNumber(wfConfig.SequenceNumber, _recId, _initialNote, NoYes::No); 

            // Set the workflow state to Submitted.
            IssueStateChangeManager::submit(args.record());
 
            ttscommit;
        }
 
        catch(exception::Error)
        {
            // ToDo Enter your code for the error action taken here.
        }
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft