How to: Create a SubmitToWorkflow Class
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, a workflow is started when the user clicks the Submit button on the workflow toolbar. The Submit button is bound to an action menu item that calls the main method on a class that you create to activate a workflow. This topic describes how to create a SubmitToWorkflow class using the workflow type name to activate the workflow.
The same procedure can be used to activate a workflow by using the workflow configuration ID or the workflow sequence number. For more information, see Activating a Workflow.
Note
If you used the Workflow Wizard to create the workflow type, a workflow submit manager class will have already been created by the wizard. You will need to add code to this class.
To create a SubmitToWorkflow class
In the Application Object Tree (AOT), expand the Classes node.
Right-click the Classes node, and then select New Class. A class group displays under the Classes node.
Right-click the new class, and then click New Method. A new method node displays under the Classes node.
Right-click the new method and then click Edit. Enter the following main method code to activate the workflow from the workflow type name. This example applies to workflow submissions for the Microsoft Dynamics AX client. For an example that also works with Enterprise Portal, see Adding Enterprise Portal Support for Workflow Submission.
public static void main(Args args)
{
// Variable declaration.
recId _recId = args.record().RecId;
WorkflowCorrelationId _workflowCorrelationId;
// Hardcoded workflow type name.
WorkflowTypeName _workflowTypeName = workflowtypestr("MyWorkflowType");
// 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 box for user comments.
workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
_recId = args.record().RecId;
// Get user comments from the submit to workflow dialog box.
_initialNote = workflowSubmitDialog.parmWorkflowComment();
try
{
ttsbegin;
// Activate the workflow from a template.
_workflowCorrelationId = Workflow::activateFromWorkflowType(_workflowTypeName, _recId, _initialNote, NoYes::No);
ttscommit;
// Updates the workflow button to diplay Actions instead of Submit.
args.caller().updateWorkflowControls();
}
catch(exception::Error)
{
// ToDo Insert your error code here.
}
}
}
Close the Editor window and click Yes to save changes.
Note
When you save this code, you will get the Empty compound statement warning message in the Compiler Output window unless you add valid code in the catch(exception::Error) block.
See also
How to: Create a New Workflow Type
Workflow::activateFromWorkflowType Method
Workflow::activateFromWorkflowSequenceNumber Method
Workflow::activateFromWorkflowConfigurationId Method
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.