Documente Academic
Documente Profesional
Documente Cultură
CHAPTER 6: WORKFLOW
Objectives
The objectives are:
Introduction
Workflow is a system in Microsoft Dynamics® AX 2012 that allows business
processes to be automated. For example, a purchase requisition may need to be
approved by a number of different employees according to the requisition's total
amount. Each employee has to approve it before the next employee in the
approval route.
6-1
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
Scenario
Isaac, the systems developer, has been asked to create a new workflow that will
be used to approve a new sales order for a customer that has reached their credit
limit. The requirement is that when a new sales order is entered which takes the
customer over their credit limit, the sales order is submitted to the Accounts
Receivable (AR) manager. They will either approve or deny the sales order. Until
it is approved, the sales order cannot be picked, packed or invoiced.
Workflow Configuration
There are three batch jobs that manage workflow processing. These jobs are all
run on the Application Object Server (AOS) using the Batch system. To set this
up, run System Administration > Setup > Workflow > Workflow
infrastructure configuration. Enter batch groups for each process. Batch groups
can be used to control which AOS instance each workflow batch job is run on.
6-2
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
Create a Query
A workflow uses a query to define the data that is used by the workflow. It can
define one or more tables and all or selected fields on that table.
6-3
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
9. Click Next.
10. Click Finish. A development project with a number of newly created
elements will be displayed.
6-4
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
You can specify conditions under which a workflow is eligible for submission.
One of these conditions must be that it has not already been submitted. To test
this condition, use a new field on the SalesTable table.
6-5
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
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;
}
6-6
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
if (workflowSubmitDialog.parmIsClosedOK())
{
recId = args.record().RecId;
SalesTable = args.record();
try
{
ttsbegin;
workflowCorrelationId =
Workflow::activateFromWorkflowType(workflowTypeName,
recId,
note,
NoYes::No);
SalesTable.CreditLimitApprovalStatus =
SalesCreditLimitApprovalStatus::Submitted;
6-7
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
ttscommit;
}
catch(exception::Error)
{
info("Error on workflow activation.");
}
}
args.caller().updateWorkFlowControls();
}
Each outcome can trigger the execution of business logic by specifying a menu
item for each item.
6-8
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
9. Click Next.
10. Click Finish. A development project with a number of newly created
elements is displayed.
11. Drag SalesCLApproval approval to the Supported elements node
on the SalesCreditLimitAppr workflow type.
12. Save your changes to the SalesCreditLimitAppr workflow type
Event handlers are implemented by creating a class that implements one or more
of the EventHandler interfaces. The interfaces at the workflow level are as
follows:
Event Description
WorkflowStarted This event occurs when the workflow instance starts.
EventHandler
WorkflowCompleted This event occurs when the workflow instance ends
EventHandler after it is completed.
6-9
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
Event Description
WorkflowCanceled This event occurs when the workflow instance ends
EventHandler after it is canceled. Use this event handler to perform
any clean up operations needed.
WorkflowConfig This event occurs when a workflow changes. Use this
DataChangeEvent event handler to identify when a workflow has
Handler changed. For example, if you create an association
between the application data and a workflow, this
event would be raised if the workflow was deleted or
updated so that application code could be invoked or
respond in some way.
Event Description
WorkflowElement This event occurs when the task or approval starts.
StartedEventHandler For approvals, you can use this event to transition
the workflow document state from Submitted to
PendingApproval.
WorkflowElement This event occurs when the task or approval is
CanceledEventHandler canceled.
For approvals, you can use this event to transition
the workflow document state from the current state
to Canceled.
6-10
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
Event Description
WorkflowElement This event occurs when the task or approval is
CompletedEvent completed.
Handler For approvals, you can use this event to transition
the workflow document state from
PendingApproval to Approved.
WorkflowElement This event occurs when the task or approval is
ReturnedEventHandler returned to the originator.
For approvals, you can use this event to transition
the workflow document state from the current state
to RequestChange.
WorkflowElemChange This event occurs when an approver requests a
RequestedEvent change to the task or approval.
Handler For approvals, you can use this event to transition
the workflow document state from
PendingApproval to RequestChange.
ttsbegin;
SalesTable.CreditLimitApprovalStatus =
SalesCreditLimitApprovalStatus::Rejected;
SalesTable.update();
ttscommit;
}
6-11
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
NOTE: Code run in batch jobs must first be compiled to the Common
Intermediate Language (CIL) of the .NET framework. This increases the
performance of the batch job.
Author a Workflow
Now that you have created a workflow type and enabled it on a form, you can
configure it for use.
6-12
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
13. Drag the bottom node of the Start box to the top node of the
Approval box.
14. Drag the bottom node of the Approval box to the top node of the
End box.
6-13
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
6-14
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
Isaac has been asked to ensure that, once a credit limit has been reached, the sales
order cannot be posted until the workflow has been approved.
Challenge Yourself!
Add conditions to the posting functions on the sales order form that will prevent
posting to picking, packing or invoicing until the workflow has been approved. If
the credit limit has not been reached, then the postings should be allowed.
Step by Step
boolean canPostCreditLimit()
{
amountMST creditBalance;
custTable custTable;
;
if (this.CreditLimitApprovalStatus ==
SalesCreditLimitApprovalStatus::Approved)
return true;
if (this.CreditLimitApprovalStatus ==
SalesCreditLimitApprovalStatus::Rejected
|| this.CreditLimitApprovalStatus ==
SalesCreditLimitApprovalStatus::Submitted)
return false;
custTable = this.custTable_InvoiceAccount();
if (!custTable.CreditMax)
return true;
creditBalance = custTable.CreditMax -
custTable.balanceMST();
if (this.amountRemainSalesFinancial() +
this.amountRemainSalesPhysical() < creditBalance)
return true;
return false;
}
6-15
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
boolean canPickingListBeUpdated()
{
......
ok = ok && salesTable.canPostCreditLimit();
return ok;
boolean canPackingslipBeUpdated()
{
......
ok = ok && salesTable.canPostCreditLimit();
return ok;
boolean canInvoiceBeUpdated()
{
......
ok = ok && salesTable.canPostCreditLimit();
return ok;
6-16
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
Isaac is required to ensure the workflow can be resubmitted after it has been
rejected.
Challenge Yourself!
When a workflow is rejected, it can be resubmitted. Modify the Submit to
Workflow class so that it can resubmit the workflow after a rejection
Step by Step
SalesCLApprovalResubmitActionMgr
SalesCLApprovalResubmitActionMgr = new
SalesCLApprovalResubmitActionMgr();
SalesCLApprovalResubmitActionMgr.resubmit(_args);
6-17
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
WorkflowWorkItemActionType::Resubmit,
new MenuFunction(menuitemactionstr(PurchReqReSubmit),
MenuItemType::Action));
workflowWorkItemActionDialog.run();
if (WorkflowWorkItemActionDialog.parmIsClosedOK())
{
_recId = _args.record().RecId;
SalesTable = _args.record();
// Get comments from the submit to workflow dialog.
_initialNote =
workflowWorkItemActionDialog.parmWorkflowComment();
try
{
ttsbegin;
WorkflowWorkItemActionManager::dispatchWorkItemAction(
_args.caller().getActiveWorkflowWorkItem(),
_initialNote,
curUserId(),
WorkflowWorkItemActionType::Resubmit,
_args.menuItemName(),
false);
SalesTable.CreditLimitApprovalStatus =
SalesCreditLimitApprovalStatus::Submitted;
6-18
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
ttscommit;
}
catch(exception::Error)
{
info("Error on workflow activation.");
}
}
_args.caller().updateWorkFlowControls();
6-19
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
Summary
The workflow system is highly configurable and flexible. By using Morph X and
some standard code patterns, it can be enabled for virtually any part of the
Microsoft Dynamics AX application.
This lesson explores some of the possibilities the workflow system offers, and
explores some of the different ways it can be used to cover most workflow
requirements.
6-20
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
2. What type of AOT element needs to be created to specify which tables will
be processed by a workflow?
( ) Extended data type
( ) Class
( ) Form
( ) Query
6-21
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
1.
2.
3.
6-22
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Chapter 6: Workflow
Solutions
Test Your Knowledge
1. What application element is used to define to which module a workflow is
applicable?
( ) Workflow type
(•) Workflow category
( ) A field in the workflow configuration
( ) SalesTable
2. What type of AOT element needs to be created to specify which tables will
be processed by a workflow?
( ) Extended data type
( ) Class
( ) Form
(•) Query
6-23
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement
Development III in Microsoft Dynamics® AX 2012
6-24
Microsoft Official Training Materials for Microsoft Dynamics®
Your use of this content is subject to your current services agreement