Creating Custom Workflows in Dynamics AX 2012

Visit Website View Our Posts

Workflows define how a business document flows through the system and indicates who must process and approve it. The workflow functionality in Microsoft Dynamics AX 2012 helps ensure that documents are processed and approved in a consistent and efficient manner. Read on to understand the workflow system in Microsoft Dynamics AX and see how you can configure, extend, and use it.

Custom Workflows in Dynamics AX 2012

Below mentioned are elements integral to the custom workflow functionality in Dynamics AX:

Workflow category

When you create a workflow type in Microsoft Dynamics AX, it must be assigned to a workflow category. The workflow category indicates if a particular workflow type is available in a specific module. If an appropriate workflow category does not already exist, you must create one.

Workflow query

You can create a query to retrieve data by using the query classes.

Workflow type

To add workflow support for a document in Microsoft Dynamics AX, you must create a workflow type. The workflow type can then be used to create workflow configurations. Workflow types should be created to define:

  • Workflow documents
  • Workflow categories
  • Tasks and approvals for the workflow
  • Event handlers such as workflow started, completed, configuration data change, and cancelled
  • A SubmitToWorkflowMenuItem

Workflow elements

Any workflow consists of certain elements that define the task or the approval process. Mentioned below are some workflow elements:

  • Base enum: To define the workflow state
  • New field in table: To maintain the workflow status as per the table record
  • canSubmitToWorkflow() method to table: To check if a record should be submitted to the workflow or not
  • Workflow properties on form: To set created workflow elements on workflow property of the related form
  • Display menu items: To create new workflows on the list page
  • Form: To perform workflow activities on the form

Creating Custom Workflows

Below is the process to create a custom workflow for a sales module where a sales order will be submitted for approval, if the credit limit for the customer related to the sales order is exceeded.

Below is the process to create a custom workflow for a sales module where a sales order will be submitted for approval, if the credit limit for the customer related to the sales order is exceeded.

1. First of all, make sure that batch jobs that handle workflow execution are running.

If batch jobs are not running, they can be started from System Administrator >> Setup >> Workflow >> Workflow infrastructure configuration.

Follow the workflow infrastructure wizard and set batch groups for all process.

2. Create workflow category

  • Expand Workflow Categories node in AOT >> Workflow.
  • Create New Workflow Category
  • Set name, label, and module properties for newly created workflow category

3. Create query

  • Expand the Queries node in AOT
  • Click on New Query
  • Set properties like Title and Description on the newly created query
  • Expand the newly created query
  • Add main data source
  • Set dynamic property of field node of added data source to Yes

4. Create workflow type

  • Expand Workflow Type node in AOT >> Workflow
  • Create New Workflow Type using workflow type wizard
  • Follow the wizard and set workflow type name, category (created in step 2), query (created in step 3) and document menu item (display menu item of form on which the workflow will be attached)
  • On clicking next, the wizard will show a list of objects that are going to be created. A new development project with new elements will be created

5. Create Base Enum

  • Expand Base Enums node in AOT >> Data Dictionary
  • Create New Base Enum for workflow states
  • Set properties of the newly created enum
  • Add elements for workflow state to enum (i.e. not submitted, submitted, approved, rejected)

6. New field in table

  • Select table (on which the workflow will work) from AOT >> Data Dictionary >> Tables
  • Add new enum type field and set enum type property to enum created in previous step
  • Compile and synchronize the table

7. canSubmitToWorkflow() method to table

  • Expand method node on table (on which the workflow will work)
  • Add/modify the canSubmitToWorklfow() method to check whether record should be added to the workflow or not. This method contains code which defines eligibility of record to submit it to workflow
  • Sample code

boolean canSubmitToWorkflow(str _workflowType = '')


amountMST creditBalance;

custTable custTable;


if (!this.CreditLimitApprovalStatus == SalesCreditLimitApprovalStatus::NotSubmitted)


return false;


custTable = this.custTable_InvoiceAccount();

if (!custTable.CreditMax)


return false;


creditBalance = custTable.CreditMax - custTable.balanceMST();

if (this.amountRemainSalesFinancial()

+ this.amountRemainSalesPhysical() < creditBalance)


return false;


return true;


8. Workflow properties on the form

  • Select Form from AOT >> Forms on workflow will be attached
  • Set properties related to workflow as below on form design

WorkflowEnabled = Yes

WorkflowDatasource = Table on which you added canSubmitToWorkflow() method

WrokflowType = Workflow type created in step 4

9. Create workflow event handler

  • Select Event Handler Class from AOT >> Classes to perform the action on sales order
  • Now, add the below code to change the workflow status, when user performs any action on workflow
  • Sample code

public void started(WorkflowEventArgs _workflowEventArgs)

{    select forupdate SalesTable

where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId();



SalesTable.INDSalesCreditLimitApprovalStatus = INDSalesCreditLimitApprovalStatus::Pending;




  • Implement same code for completed and canceled method

10. Add element level event handler

  • Select Event Handler Class from AOT >> Classes to perform the action on sales order
  • When work flow status is updated, update the sales order enum element as well
  • Sample code

public void started(WorkflowElementEventArgs _workflowElementEventArgs)



select forupdate SalesTable

where SalesTable.RecId == _workflowElementEventArgs.parmWorkflowContext().parmRecId();



SalesTable.INDSalesCreditLimitApprovalStatus = INDSalesCreditLimitApprovalStatus::PendingApproval;





  • You need to perform this action on completed, change requested, canceled, created, denied and returned method in the event handler class

11. Drag workflow approval to workflow type

  • Go to workflow node from the AOT. Select workflow element from the workflow elements node and then after drag this element into the workflow types - >Supported elements node like the following image

12. Workflow author

  • Create new display menu items. Go to AOT >> Menu Items >> Display.
  • Change the following properties in the display menu item.
    1. Set the label to "Sales order credit limit work flow"
    2. Set the object to WorkflowTableListPage
    3. Set the EnumTypeParameter to ModuleAxapta
    4. Set the EnumParameter to Basic

  • Now drag display menu items in the home context area page
  • Set the IsDisplayedInContentArea to Yes
  • Perform the incremental CIL

13. Create and enable workflow for sales order

  • Select Display Menu Items which have previously been created and open it
  • Select New button to select workflow from the list
  • Select the Work Flow Type from the list and click on Create Workflow

14. Design workflow

  • Drag and drop the approvals from the Workflow Elements window to the Workflow window
  • Drag the bottom node of the Start box to the top node of the Approval box
  • Drag the bottom node of the Approval box to the top node of the End box

  • Now double click on the Approval box
  • Select Step from the workflow elements. Select Assignment
  • On the Assignment type tab, select User. On the User tab, select the user and drag user into the selected user list
  • Click on Basic Settings and then enter subject and instructions for the approval
  • Click on Save and Close
  • Enter workflow notes and click Ok
  • Then click on Activate the New Version and click Ok

15. Now create a new sales order and check for the workflow – it will be activated in your new sales order

Ensure Efficient Workflows

Workflows are important to any organization; by providing the functionality to create business processes, they define how a document flows through the system by showing the steps needed to process and approve it along with who needs to process it. In Dynamics AX, you can define workflow categories, types and elements to create custom workflows, and ensure all documents pertaining to your business are processed and approved in the most efficient manner.

New call-to-action

Related Articles:

About the Author - Angna Thakkar

Angna Thakkar is a competent Senior Project Manager, Microsoft Dynamics AX Technical at Indusa with over 10 years of experience in managing multi-disciplinary teams of varying sizes and complex programs of work. She is always committed to professionalism, highly organized, able to see the big picture while paying attention to small details.


Contributing Author: Malavika Nityanandam

2 thoughts on “Creating Custom Workflows in Dynamics AX 2012”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Show Buttons
Hide Buttons