0% found this document useful (0 votes)
27 views

AX 2012 Create Custom Workflow Microsoft Dynamics AX

This document provides steps to create a custom workflow in Microsoft Dynamics AX 2012. It involves: 1. Creating base enums and a student fee table with approval status and workflow status fields. 2. Overriding the canSubmitToWorkflow method and creating forms and queries. 3. Creating a workflow category, type, and methods to submit, start, complete and cancel the workflow. 4. Updating code for workflow events and approval events to update the record status. 5. Configuring the form and menu items to enable the workflow.

Uploaded by

Khorusaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

AX 2012 Create Custom Workflow Microsoft Dynamics AX

This document provides steps to create a custom workflow in Microsoft Dynamics AX 2012. It involves: 1. Creating base enums and a student fee table with approval status and workflow status fields. 2. Overriding the canSubmitToWorkflow method and creating forms and queries. 3. Creating a workflow category, type, and methods to submit, start, complete and cancel the workflow. 4. Updating code for workflow events and approval events to update the record status. 5. Configuring the form and menu items to enable the workflow.

Uploaded by

Khorusaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Microsoft Dynamics AX

Dynamics AX development notes,stuff, tips, tricks,


tutorials,development tools

AX 2012: Create Custom Workflow

June 2, 2016 · by Mohammad Arif · in Uncategorized, X++. ·

Workflow is defined as the movement of documents or tasks through a work process.

In Microsoft Dynamics AX, workflow is structured and based on user interaction and system
automation of business data.

I have Student Fee Collection Table and School Administration wants Approval Process,

If fee is pending then they are not allow for next semester etc.

Base Enums

(1) Create “CustFreeInvoiceWFApprovalStatus” base enums for the workflow approval status
Create “FStatus” base enums for the workflow approval status

(2) Create New Table “studen�able”

Field Datatype
Id Integer
Name String
Fee Real, Extended Datatype= AmountMST
FStatus Enum, Enum Type= FStatus
Enum,Enum Type=
WorkflowStatus
CustFreeInvoiceWFApprovalStatus
Override Method on “studen�able” Table

Override canSubmitToWorkflow method on studen�able

public boolean canSubmitToWorkflow(str _workflowType = ”)

boolean ret;

if(this.FStatus==FStatus::Inreview)

ret=true;

return ret;}

(3) Create Query “studentQuery”


(4) Create simple list form “StudentForm”

(6) Create New Menu Item->Display->Studentmenu

(7) Workflow Category:

AOT–>workflow–>Workflow Categoiesàcreate new “StudentWFCategory”


(8)Workflow Type: “studentwft”

AOT–>Workflow–>Workflow type–>Right Click–>Add-Ins–>WorkFlow type Wizard–>Next

This will create a private project ,

After the workflow type is created, add code for the workflow events.

Add below code to the studentwftSubmitManager class on workflow type project

(9)Create one method “Submit”

void submit(Args args)

// Variable declaration.

recId recId = args.record().RecId;

WorkflowCorrelationId workflowCorrelationId;

// Hardcoded type name

WorkflowTypeName workflowTypeName =workflowtypestr(“studentwft”);

// Initial note is the information that users enter when they

// submit the document for workflow.

WorkflowComment note =””;

WorkflowSubmitDialog workflowSubmitDialog;

studen�able stable;

//CustInvoiceLine custInvoiceLine;
// Opens the submit to workflow dialog.

workflowSubmitDialog
=WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());

workflowSubmitDialog.run();

if (workflowSubmitDialog.parmIsClosedOK())

recId = args.record().RecId;

stable = args.record();

// Get comments from the submit to workflow dialog.

note = workflowSubmitDialog.parmWorkflowComment();

try

�sbegin;

workflowCorrelationId
=Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Submi�ed;

// Send an Infolog message.

info(“Submi�ed to workflow.”);

�scommit;

catch(exception::Error)

info(“Error on workflow activation.”);

args.caller().updateWorkFlowControls();

(10) Goto “main” method of class

public static void main(Args args)

{
studentwftSubmitManager SubmitManager =new studentwftSubmitManager();

SubmitManager.submit(args);

(11) Update code on studentwftEventHandler class for different events

Add below code on completed method

public void completed(WorkflowEventArgs _workflowEventArgs)

studen�able stable;

RecId SRecId;

SRecId =_workflowEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Completed;

stable.FStatus=FStatus::Approve;

stable.update();

�sCommit;

Add below code on started method

public void started(WorkflowEventArgs _workflowEventArgs)

studen�able stable;

RecId SRecId;

SRecId =_workflowEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Pending;

stable.FStatus=FStatus::Pending;

stable.update();

�sCommit;
}

Add below code on canceled method

public void canceled(WorkflowEventArgs _workflowEventArgs)

studen�able stable;

RecId SRecId;

SRecId =_workflowEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Cancellation;

stable.FStatus=FStatus::Cancel;

stable.update();

�sCommit;

(12) Update Lables on Menuitems

studentwftSubmitMenuItemàproperties à set label as Submit-WFT

studentwftCancelMenuItemàpropertiesà set label as Cancel-WFT

***************************************************************************

(13) Enable workflow on form


Goto Form “StudentForm” ->Design->properties

Workflowenabled=Yes ,

workflowdatasource= studen�able

workflowtype= studentwft

(14) Workflow Approval:

Open the AOT.–>Expand the Workflow node.–>

Right-click on Approvals and select Add-ins > Approval wizard.

Click Next.

This wizard will create the private project as below:


(15) Now, Update code on studentApprovalEventHandler for different events

public void completed(WorkflowElementEventArgs _workflowElementEventArgs)

studen�able stable;

RecId SRecId;

SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Completed;

stable.FStatus=FStatus::Approve;

stable.update();

�sCommit;

public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)

studen�able stable;

RecId SRecId;

SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Cancellation;

//stable.FStatus=FStatus::Cancel

stable.update();

�sCommit;}

public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)

studen�able stable;

RecId SRecId;

SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();
�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::ChangeRequested;

stable.update();

�sCommit;

public void denied(WorkflowElementEventArgs _workflowElementEventArgs)

studen�able stable;

RecId SRecId;

SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Rejected;

stable.FStatus=FStatus::Cancel;

stable.update();

�sCommit;

public void returned(WorkflowElementEventArgs _workflowElementEventArgs)

studen�able stable;

RecId SRecId;

SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Rejected;

stable.update();

�sCommit;

}
public void started(WorkflowElementEventArgs _workflowElementEventArgs)

//WorkflowElementStartedEventHandler

studen�able stable;

RecId SRecId;

SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();

�sBegin;

select forUpdate stable where stable.RecId == SRecId;

stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::PendingApproval;

stable.FStatus=FStatus::Pending;

stable.update();

�sCommit;

(16) Update Lables on Menuitems

studentApprovalApprove set label as Approve

studentApprovalRejectset label as Reject

studentApprovalRequestChange set label as Request change

studentApprovalDeny set label as ApprovalDeny

(17) Drag workflow approval to workflow type

Drag workflow approval “studentApproval” to workflow type under studentwft> Supported


elements
(18)Create Menu for Menu itemàDisplayà“Studentworkflow”

(19)Drag and Drop Menu items ” Studentworkflow” in “Home” Menu

(20)Drag and Drop Menu items ” Studentmenu” in “Home” Menu

(21)Start Compile , AOT–>Right click–> incremental CIL compile

(22)Open Work Flow: menu and student Form


Advertisement
Explosive HSBC files could help Trump

In view of the court case against Donald


Trump, Augenauf.blog will publish the
explosive HSBC files. These incriminate
the New York judicial system and others.

Tags: Create Custom Workflow, workflow

One response to “AX 2012: Create Custom Workflow”

1. Pingback: AX 2012: Create Custom Workflow | Microsoft Dynamics AX·

Blog at WordPress.com.

You might also like