How to: Activate a Workflow using the Sequence Number
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
In Microsoft Dynamics AX, workflow can be activated by using a workflow type, 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 type 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:
Create an action menu item.
Bind the action menu item to the workflow type.
Create and implement a class to activate the workflow.
Associate the action menu item with the class.
To create an action menu item and bind it to the workflow type
In the AOT, expand the Menu Items node.
Right-click the Action node, and then click New Menu Item. An action menu item displays under the Menu Items node.
Right-click the new action menu item and then click Properties.
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.
In the AOT, expand the Workflow node, and then expand the Workflow Types node.
Right-click the workflow type that you want to bind an action menu item to and then click Properties.
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
In the AOT, right-click the Classes node, and then click New Class. A new class displays under the Classes node.
Right-click the new class, click Rename, and then enter a name.
Right-click the new class and then click New Method. The Editor window opens.
In the Editor window, insert the code for the action to take to activate the workflow by using a configuration sequence number.
Note
See the code example in the following example that contains a static main method implementation for an issue handling workflow.
In the AOT, expand the Menu Items node.
Expand the Action node, and then select the action menu item to implement the class created in the previous procedure.
In the Properties sheet, set the Object property to the name of the class to activate the workflow.
Example
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 type.
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;
WorkflowConfiguration wfConfig;
WorkflowSequenceNumber workflowSequenceNumber;
// 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::activateFromWorkflowSequenceNumber(wfConfig.parmWorkflow().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.
}
}
}
See also
How to: Create a New Workflow Type
Requirements for Enabling Workflow in an Application Module
Workflow::activateFromWorkflowSequenceNumber Method
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.