Workflow LifeCyle

Problem Statement:

How to create a new custom workflow. A simple and easy guide to create a new customer approval workflow. By following this guide, the reader can implement a custom workflow in AX 2012 with ease.

Workflow Development Process

Workflow LifeCyle

Lets develop workflow for ‘Customer approval’

OBJECT :  ‘New created customer should be approved through workflow’

To develop a new workflow, following artifacts or objects need to be created / modified:

  •          Workflow Categories
  •          Workflow Templates
  •          Workflow Query (Document)
  •          Workflow Approvals and Tasks (Tasks are optional)
  •          Enabling the workflows on the form
  •          Workflow submission classes

 

Step 1: Create a query for custTable  CustApprovalWorkflowQuery

           AOT->Queries

Step 2: Create a new Enumeration and name it says ‘CustApprovalWorkflowState‘ and add it in CustTabel

Workflow-State

 

Step 3: Override ‘canSubmitToWorkflow‘ method on Table-> CustTable and code it like :

public boolean canSubmitToWorkflow(str _workflowType = ‘ ‘)
{
boolean ret;

ret = this.RecId != 0 && this.CustApprovalWorkflowState==
CustApprovalWorkflowState::NotSubmitted;

return ret;
}

Create new method on CustTable as below to update worklow state during its life cycle.

public static void UpdateCustWorkflowState(RefRecId _recId, CustApprWorkflowState _state)
{
CustTable custTable = CustTable::findRecId(_recId, true);

ttsBegin;

custTable.CustApprovalWorkflowState= _state;
custTable.update();

ttsCommit;
}

Step 4 : Create workflow type (configuration) through wizard available in 2012.

Run wizard as below:
AOT->Workflow-> Workflow types  (Right click ->Add-Ins-> workflow type wizard

Workflow Wizard

Specify Wizard values  and By Clicking on next,  wizard will create workflow eventhandlers class and menu items for you.

Use Below Code to Update Workflow State

public void started(WorkflowEventArgs _workflowEventArgs)
{

CustTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(),CustApprovalWorkflowState::Submitted);

}
public void completed(WorkflowEventArgs _workflowEventArgs)
{

CustTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), CustApprovalWorkflowState::Completed);
}
public void canceled(WorkflowEventArgs _workflowEventArgs)
{
CustTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(),              CustApprovalWorkflowState::PendingCancellation);
}

Step 5:  Create workflow approval through wizard available in 2012.

Run wizard as below:

AOT->Workflow-> Approvals  (Right click ->Add-Ins-> Approval wizard

Workflow Approval Wizard

 Specify values  and by Clicking on next,  wizard will create workflow eventhandlers class and menu items for you.

Workflow_Approval_1

 

  • Expand the Supported elements node of Workflow Type and drag and drop the WorkFlow Approval there.

Use below code to update workflow state.

public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{    CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),   CustApprovalWorkflowState::Submitted);
}
public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),  CustApprovalWorkflowState::Returned);
}
public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),  CustApprovalWorkflowState::ChangeRequest);
}
public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), CustApprovalWorkflowState::Approved);
}
public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{

CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),  CustApprovalWorkflowState::PendingCancellation);
}

 

Step 6 Enable workflow on CustTableListPage form and also add field CustApprovalWorkflowstate on form overview grid.

CustTableListPage->Design, set properties as below

Workflow_Form_Enable

Step 7:  Now Create a simple Worklow

Now that we have created a simple workflow, we can actually create a simple approval workflow  through the workflow designer

Account receivable -> Setup

aos-

Click on New button and select Your Workflow Type in our case which is Cust Approval Workflow,

Drag  Cust Approval from the workflow element to the Workflow and join  Cust Approval from start node and end node

Workflow Screen

Step 9 :  Do Necessary Settings to enable work flow  

  • Select Assignment type to workflow user or any other user.
  • Enter Message Text for all work items.
  • Specify when notifications will sent to user.

Make sure there will be no error in the workflow , you can check errors from error pane .

error pane

 Final Step : Run Incremental CIL generation,

 AOT->Right click-> Incremental CIL generation

You are done with development and configuration of workflow .

 

Problems encountered :

  • Workflow Approval doesn’t appear in the workflow design form :

Solution  : Expand the Supported elements node of Workflow Type and drag and drop the Workflow Approval there.

Sol

 

  • You Must Restart Your  AOS after Developing and configuring Workflow. This will avoid any possible issues (if any).

Leave a Reply

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

Recent Comments

    Archives

    Categories