Walkthrough: Adding an Automated Task to a Workflow
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, you can add automated tasks to a workflow in the Application Object Tree (AOT). In this walkthrough, you will create and add an automated task to the MyWorkflowType based on the CustTable form. This walkthrough builds on the Walkthrough: Creating a Workflow Type, the Walkthrough: Adding Workflow to an Existing Form, and the Walkthrough: Creating a Workflow with a Task and an Approval.
This walkthrough illustrates the following tasks:
Creating an automated task.
Writing code that is run when the automated task is executed.
Configuring a workflow on the client to run the automated task.
Prerequisites
To complete this walkthrough, you will need:
Microsoft Dynamics AX
A license file that has access to the MorphX development environment.
To complete the steps in Walkthrough: Creating a Workflow Type.
To complete the steps in Walkthrough: Adding Workflow to an Existing Form.
To complete the steps in Walkthrough: Creating a Workflow with a Task and an Approval.
To Create an Automated Task
In the AOT, expand the Workflow node.
Right-click the Automated Tasks node and then select New Automated Task. A new workflow automated task group displays under the Automated Tasks node.
Right-click the new workflow automated task and then click Properties.
In the Properties sheet, set the following properties:
Property
Value
Name
MyWorkflowAutomatedTask
Label
MyWorkflowAutomatedTask
Document
MyWorkflowDocumentClass
Note
This value is available only if you complete Walkthrough: Creating a Workflow Type.
In the AOT, right-click MyWorkflowAutomatedTask, and then click Save.
To Create a Class To Handle Automated Task Events
In the AOT, right-click Classes and select New Class. A new class displays under the Classes node.
Right-click the newly created class and select Properties.
In the Properties sheet, set Name to MyWorkflowAutomatedTaskEventHandler.
Expand the MyWorkflowAutomatedTaskEventHandler class. Double-click the classDeclaration node. The Code Editor opens.
Type the following code into the Code Editor:
class MyWorkflowAutomatedTaskEventHandler implements WorkflowElementExecutionEventHandler { }
Warning
You can also implement the WorkflowElementCanceledEventHandler event handler, but it is not required.
In the AOT, right-click MyWorkflowAutomatedTaskEventHandler and select New Method. A new method appears under the class.
Double-click the new method. The Code Editor opens.
Type the following code in the Code Editor:
public void execute(WorkflowElementEventArgs _workflowElementEventArgs) { // This is the variable declaration. WorkflowContext workflowContext; ; // Gets the workflow context from _workflowElementEventArgs. workflowContext = _workflowElementEventArgs.parmWorkflowContext(); }
In the Code Editor, press the Save button. You can now close the Code Editor.
You now need to update the automated task to set the ExecutionEventHandler property to the class that you just created. In the AOT, expand the Workflow node, and then expand the Automated Tasks node. Right-click MyWorkflowAutomatedTask and select Properties.
In the Properties sheet, set the ExecutionEventHandler property to MyWorkflowAutomatedTaskEventHandler.
Right-click the MyWorkflowAutomatedTask node and select Save.
To compile your application, in the AOT, right-click AOT, select Add-Ins, and then select Incremental CIL generation from X++.
Next Steps
You can expand this walkthrough by adding a CanceledEventHandler to the automated task. For more information, see How to: Create a Workflow Task or Approval Event Handler.
See also
Walkthrough: Creating a Workflow Type
Walkthrough: Adding Workflow to an Existing Form
Walkthrough: Creating a Workflow with a Task and an Approval
Requirements for Enabling Workflow in an Application Module
Creating Workflow Tasks, Automated Tasks, and Approvals
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.