Compartilhar via


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:

To Create an Automated Task

  1. In the AOT, expand the Workflow node.

  2. Right-click the Automated Tasks node and then select New Automated Task. A new workflow automated task group displays under the Automated Tasks node.

  3. Right-click the new workflow automated task and then click Properties.

  4. 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.

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

To Create a Class To Handle Automated Task Events

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

  2. Right-click the newly created class and select Properties.

  3. In the Properties sheet, set Name to MyWorkflowAutomatedTaskEventHandler.

  4. Expand the MyWorkflowAutomatedTaskEventHandler class. Double-click the classDeclaration node. The Code Editor opens.

  5. 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.

  6. In the AOT, right-click MyWorkflowAutomatedTaskEventHandler and select New Method. A new method appears under the class.

  7. Double-click the new method. The Code Editor opens.

  8. 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();
    }
    
  9. In the Code Editor, press the Save button. You can now close the Code Editor.

  10. 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.

  11. In the Properties sheet, set the ExecutionEventHandler property to MyWorkflowAutomatedTaskEventHandler.

  12. Right-click the MyWorkflowAutomatedTask node and select Save.

  13. 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.