Академический Документы
Профессиональный Документы
Культура Документы
Introduction
Workflow is a module in Microsoft Dynamics AX 2009, that allows flexible task and approval routes for documents created by users. For example, a purchase requisition may need to be approved by a number of different employees according to the requisition's total amount, and each employee has to approve it before the next employee in the approval route. A Workflow in Microsoft Dynamics AX uses a combination of AOT elements created by IT, and configuration that may be set up by a user. This lesson introduces the development side of creating an workflow, for which you will need to use skills developed from this class and the Morph X development class.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-1
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 that takes the customer over their credit limit, the sales order should be 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 Installation
A number of the workflow system components are required to be installed before you can begin to create and configure workflows in Microsoft Dynamics AX. Workflow website. This is an IIS website that controls the flow of the workflows. Workflow accounts. There are two accounts used - a system account used to provide access to the workflow tables, and an execution account that is used to execute business logic. Microsoft Dynamics AX workflow server component. This is the workflow engine and is installed using the Microsoft Dynamics AX installation files. The website and the accounts are required to run this installation.
NOTE: This course does not cover the installation of the workflow system components; however you need to be aware of the requirements. For more information about workflow installation, refer to the Administrator Guide.
11-2
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
FIGURE 11.1
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-3
FIGURE 11.2
11-4
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-5
FIGURE 11.3
11-6
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
FIGURE 11.4
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-7
11-8
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
1. 2. 3. 4. 5. 6. 7. 8. 9.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-9
11-10
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-11
WorkflowCanceledEventHandler
WorkflowConfigDataChangeEventHandler
11-12
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
public void cancelled(WorkflowEventArgs _workflowEventArgs) { SalesTable SalesTable; ; ttsbegin; select forupdate SalesTable where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId(); SalesTable.CreditLimitApprovalStatus = SalesCreditLimitApprovalStatus::NotSubmitted; SalesTable.update(); ttscommit; } public void completed(WorkflowEventArgs _workflowEventArgs) { SalesTable SalesTable; ; ttsbegin; select forupdate SalesTable where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId(); if (salesTable.CreditLimitApprovalStatus == SalesCreditLimitApprovalStatus::Submitted) { SalesTable.CreditLimitApprovalStatus = SalesCreditLimitApprovalStatus::Approved; SalesTable.update(); } ttscommit; }
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-13
public void returned(WorkflowEventArgs _workflowEventArgs) { SalesTable SalesTable; ; ttsbegin; select forupdate SalesTable where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId(); SalesTable.CreditLimitApprovalStatus = SalesCreditLimitApprovalStatus::Rejected; SalesTable.update(); ttscommit; } public void started(WorkflowEventArgs _workflowEventArgs) { SalesTable SalesTable; ; ttsbegin; select forupdate SalesTable where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId(); SalesTable.CreditLimitApprovalStatus = SalesCreditLimitApprovalStatus::Submitted; SalesTable.update(); ttscommit; }
11-14
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
WorkflowElementCanceledEventHandler
WorkflowElementCompletedEventHandler
WorkflowElementReturnedEventHandler
WorkflowElemChangeRequestedEventHandler
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-15
class SalesCreditLimitElementHandler implements WorkflowElementCompletedEventHandler, WorkflowElementCanceledEventHandler, WorkflowElementReturnedEventHandler, WorkflowElemChangeRequestedEventHandler, WorkflowElementStartedEventHandler { } public void returned(WorkflowEventArgs _workflowEventArgs) { SalesTable SalesTable; ; ttsbegin; select forupdate SalesTable where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId(); SalesTable.CreditLimitApprovalStatus = SalesCreditLimitApprovalStatus::Rejected; SalesTable.update(); ttscommit; }
11-16
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Configure a Workflow
Now that you have created a template and enabled it on a form, you can configure it for use.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-17
11-18
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
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
1. Add the following method CanPostCreditLimit to the salesTable table. 2. Add the following code to the methods canPickingListBeUpdate(), canPackingSlipBeUpdated() and canInvoiceBeUpdated() in the salesTableType class.
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;
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-19
11-20
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
The tableId that the workflow is to be performed on is retrieved from the query specified in the workflow document class. The workFlowContext class holds all the relevant data for the workflow submission. The SysWorkFlowEventDispatcher class creates records that will be read by the Workflow Processor class to determine which actions should be executed in the next step of the workflow.
workflowContext = WorkflowContext::newRootWorkflowContext(curext(), tableId, _recId, correlationId); try { SysWorkflowEventDispatcher::onWorkflowSubmit(workflowContex t, _submittingUser, configTable.ConfigurationId, _initialNote, _activatingFromWeb); }
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-21
All records due for processing are retrieved. The WorkflowWorkItem::escalateWorkItem() is called 2. View the method WorkflowWorkItem::escalateWorkItem()
try { workItemId = SysWorkflowEventDispatcher::onWorkItemEscalation(_workItemC ontext); }
The workItemTable record is retrieved. This is the next pending activity on the workflow, based on the configuration.
11-22
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-23
Challenge Yourself!
When a workflow is rejected, it should be able to be resubmitted. Modify the Submit to Workflow class so that it can resubmit the workflow after a rejection Use the PurchReqWorkflow class as inspriration.
Step by Step
1. Create a new action menu item called SalesCreditLimitResubmit 2. Set the ObjectTypePropety to class, the Object property to SalesCreditLimitSubmit and the Label property to Resubmit. 3. Modify the Main method on the SalesCreditLimitSubmit class and add a new method Resubmit as follows: 4. On the SalesCreditLimitApproval approval element, set the ResubmitMenuItem property to SalesCreditLimitResubmit
public static void main(Args _args) { SalesCreditLimitSubmit SalesCreditLimitSubmit = new SalesCreditLimitSubmit(); ; if (_args.menuItemName() == menuitemactionstr(SalesCreditLimitSubmit)) { SalesCreditLimitSubmit.submit(_args); } else { SalesCreditLimitSubmit.resubmit(_args); } } void resubmit(Args args) { // Variable declaration. recId _recId = args.record().RecId; WorkflowCorrelationId _workflowCorrelationId; // Hardcoded template name WorkflowTemplateName _workflowTemplateName = workflowtemplatestr(SalesCreditLimitApproval);
11-24
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
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; // Send an Infolog message. info("Resubmitted to workflow.");
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-25
Summary
The workflow module is a highly configurable and flexible module. However, by using Morph X and some standard code templates, it can be configured for any part of the Microsoft Dynamics AX application. This lesson explores some of the possibilities the workflow framework offers, and explores some of the different ways it can be used to cover most workflow requirements.
11-26
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-27
2.
3.
11-28
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Solutions
Test Your Knowledge
1. Which application element is used to define to which module a workflow is applicable? ( ) Workflow template () Workflow category ( ) A field in the workflow configuration ( ) SalesTable 2. Which type of AOT element needs to be created to specify which tables will be affected by a workflow? ( ) Extended data type ( ) Class ( ) Form () Query 3. There are three types of providers that define what rules the workflow can follow. What are they? () Participant provider () DueDate provider () Hierarchy provider ( ) Internet provider 4. Which two properties on a form data source need to be modified to allow the form to use a workflow? ( ) WorkflowTemplate () WorkflowEnabled ( ) WorkflowDocument () WorkflowDatasource
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-29
11-30
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement