Beruflich Dokumente
Kultur Dokumente
Introduction
Workflow in Microsoft Dynamics AX 2012 uses a combination of Application Object Tree (AOT) elements created by the developer and additional set up that is completed by the end-user to control the configuration and process a workflow will follow. This course introduces advanced development topics that explain how to implement line-item workflows, create workflow work item queues, create new workflow providers, implement currency support in the Condition Editor, and implement conditions on fields that represent hierarchies in the Condition Editor.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-1
Line-Item Workflows
Workflows act on business documents. Sometimes patterns exist where there is a relationship between two tablesone is a header table; for example, Expense header, and the other is a line-item table. The line-item table contains records that relate to the header, for example, an expense report has many expense lines. Line-item workflow in Microsoft Dynamics AX 2012 supports this header and line pattern. The developer must enable line-item support for each workflow where a header and line-item relationship exists. Then the business user can configure a workflow that includes a "Line-item workflow" element. In that element, the business user can select the workflows that he or she wants to act on the line items. For example, some transactions might be processed by using a project approval workflow, others might be processed by using a workflow that only requires approval by the manager. End-users interact with line-item workflows in the same manner as other workflowsby taking workflow actions on the line items. NOTE: Some tables are enabled for line-item workflows out of the box, such as purchase requisitions and expense reports.
11-2
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-3
Workflow Providers
Workflow providers in Microsoft Dynamics AX provide application specific data for a workflow at run time. The application data provided can include the following: User IDs based on user groups. Due dates based on employee or manager working days. Specific user or manager IDs based on their maximum approval limits. Groups of users assigned to a specific work item queue.
The following topics describe the default workflow providers in Microsoft Dynamics AX and how to implement them.
11-4
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Each task or workflow must have a due date provider defined to determine the last date by which the workflow element can be compeleted. For example, the maximum number of days to complete a task, or the maximum time permitted to wait for an approval before automatic denial of the approval. A provider is also used to select a user or group of users for the task or approval step. For example, the participant provider could select a manager from a manager's role to approve an expense report. In Microsoft Dynamics AX 2012 the providers for a workflow element are inferred. There are no special parameters that must be set on the elements in the AOT to specify the type of provider. Each workflow element can have many different types of providers available. However, only one type of provider can be selected when configuring a workflow element. The WorkflowHierarchyProvider.getNextNode method is called when an approval or task is started to retrieve the identity of the user in the hierarchy that should be assigned a work item. The WorkflowHierarchyProvider.getNodeDataType method is called when the approval or task is started to return an object of the type the hierarchy provider expects as input. Because each hierarchy provider implementation can have a different input type, the input type is based on the type of hierarchy. For example, an organizational hierarchy provider might return employee ID, whereas a product hierarchy provider might return a product ID. The WorkflowHierarchyProvider.convertToNodeDataType method is called at run time when an extended data type value must be converted to a data type that the hierarchy supports as the start node.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-5
The WorkflowDueDateProvider.getCalendarTokens method is called from the workflow configuration user interface so that the user can select a calendar from the list of supported calendars. This method provides a list of the calendars IDs from a calendar system, such as the calendar defined in the Organization administration module's Calendars form. The WorkflowDueDateProvider.Resolve method is called when a task or approval step is started to determine the due date of the step. For example, the workflow configuration is set up to require an expense report approval within 10 work days. When the approval step or task is started, the due date provider's resolve method is called to return the actual due date. The calendar ID specified in the configuration user interface is passed into this method to resolve the time span for a workflow work item into the due date for the work item based on the calendar ID.
11-6
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Participant Provider
You can use a participant provider to return a list of users from any abstraction, such as a user group. Microsoft Dynamics AX workflow provides the WorkflowUserGroupParticipantProvider class that returns a list of users based on a Microsoft Dynamics AX user group. The WorkflowUserGroupParticipantProvider class implements the WorkflowParticipantProvider interface that contains the following methods: WorkflowParticipantProvider.getParticipantTokens WorkflowParticipantProvider.resolve
The WorkflowParticipantProvider.GetParticipantTokens method is called from the workflow configuration user interface to display a list of supported participant tokens. Participant tokens are IDs of user roles or user group names. When you implement a customer provider, the participant token represents the abstraction when you implement a different concept. For example, if you implemented a new provider for commission groups, the IDs could represent the commission group ID. The WorkflowParticipantProvider.Resolve method is called when a task or approval step is started to determine the specific user who will complete the step. For example, the workflow configuration is set up to require the approver of a step to be the purchasing manager. When the approval step is started, the participant provider resolve method is called to return the user ID of a specific purchasing manager.
Queue Provider
You can use a queue provider to return a list work item queues that are configured in the Home module. Microsoft Dynamics AX workflow provides the WorkflowQueueProvider class that returns a list of work item queues. The WorkflowWorkItemQueueProvider class implements the WorkflowQueueProvider interface which contains the following methods: WorkflowParticipantProvider.getQueueTokens WorkflowParticipantProvider.queueIDToQueueName WorkflowParticipantProvider.queueNameToQueueID WorkflowParticipantProvider.resolve
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
5. Right-click in the Code Editor window, click New, and then enter the following code for the getParticipantTokens method.
public WorkflowParticipantTokenList getParticipantTokens() { // Constructs the new user group list. WorkflowParticipantTokenList userGroups = WorkflowParticipantTokenList::construct(); ; // ToDo Define your user groups here. return userGroups; }
6. Right-click in the Code Editor window, click New, and then enter the following code for the resolve method.
public WorkflowUserList resolve(WorkflowContext _context, WorkflowParticipantToken _participantTokenName) { // Declare the variables. UserGroupList userGroupList; WorkflowUserList userList = WorkflowUserList::construct(); ; // Verify that the participant token is set or throw an error. if (!_participantTokenName) throw error("@SYS105453"); // ToDo Enter code to add users to the user list. { } userList.add(userGroupList.UserId);
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-9
7. Close the Code Editor window and then click Yes to save the changes.
Developer Actions
The developer must complete the following high level steps to enable queues for a document. 1. Enable queues in the workflow document by setting the following attribute on the workflow document class in the class declaration WorkflowDocIsQueueEnabledAttribute(true,"<label>") a. <label> is the label ID that represents the business document name. b. The business document name tells the workflow system that any workflows based on this workflow document can have work items generated that are assigned to a queue. 2. Next, create a custom WorkflowQueueCreatedEventHandler class. This is necessary to store additional data that is used when you view the work items that are assigned to a queue in the user interface. a. The custom class must derive from the base class WorkflowQueueCreatedEventHandler b. You have to override the mapFields() method HINT: For an example of how to implement this, refer to the TrvDocumentQueuedTaskEventHandler class in AOT. The mapFields method is overridden to set the DocumentID, Type and Company. 3. Set the WorkItemsCreatedEventHandler property on the task element in AOT with the custom WorkflowQueueCreatedEventHander class created previously. This guarantees that it is used at run time. 4. Create custom list page queries to allow for filters based on queue assignment.
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
11-12
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Demonstration: Link the Workflow Queue Event Handler to the Workflow Type
After you have created an event handler for the work item queue, you have to link the new event handler class to the task or approval in the AOT. To link the workflow event handler to a workflow task, follow these steps. 1. In the AOT, expand the Workflow node, and then expand the Tasks node. 2. Select the task that you want to allow work item queues for, or if it does not exist, create a new task and set the properties as required. 3. Right-click the task and select Properties. 4. Set the WorkItemsCreatedEventHandler property to the event handler class that you created in Demonstration: Create a Workflow Queue Event Handler. 5. Save the Task. NOTE: Queues are not supported for approval elements because the way users interact with them is different than tasks.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-13
11-14
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
For other examples of queries and list pages that you can add to a document, refer to the Purchase requisition list pages that are located in Procurement and sourcing > Common > Purchase requisitions.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-15
The most basic approach to implementing currency fields in the Condition Editor is to set meta-data that will be used by the default currency provider. This metadata is then used by the Condition Editor together with a default currency provider without any additional development. This is true only when the currency code field is on the same table as the currency amount field. In all other cases, coding is required to either extend the default currency provider implementation or to implement a new currency provider that meets your application needs.
11-16
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
NOTE: There are no additional steps required to implement this scenario. However, this scenario will only be used if the method described in the Currency Code scenario does not apply, and there is no calculated field that returns the currency code. IMPORTANT: A "global" or system currency code is not supported in the base implementation. Therefore, you must implement a new currency provider or extend the default currency provider if this is a requirement.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-17
IMPORTANT: A relation must be defined on the field that stores the currency codes. This relation is used by the system to create a lookup for currency codes in the Condition Editor. If a relation does not exist, the ellipses button will not appear in the Condition Editor and the user cannot select the currency code from a list.
11-18
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-19
Line 3 is the ExpressionCurrencyFieldMapAttribute which is used to set the currency code and currency value. The two parameters that are being passed in are value and the currency code. In this example, there are two methods in the class that define what the currency code and values are. The parmTotalExpenseAmount method returns the total amount of the expense report by calling the total() method on the TrvExpTable for the record that is passed in. The parmAccountingCurrencyCode method returns the accounting currency in the Ledger form for the legal entity that is linked to either the expense line or the expense header, depending on the record that is passed in. This method is also decorated with the ExpressionFieldHideAttribute which is used to hide the currency code field in the Condition Editor. This prevents the user from selecting a different currency than the currency that is selected on the transaction that is passed in. Lines 4 and 5 use the ExpressionCurrencyLEAttribute which sets the legal entity for a table that is passed in. The legal entity is used by the ExpressionCurrencyDefaultProvider to perform the conversion in the Condition Editor. Each data source in the document query that included amounts that need currency conversion support must have their own attribute defined. In this example, there are two data sources-one for the expense header (TrvExpTable) and one for the expense lines (TrvExpTrans).
11-20
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
In this example, the first condition is comparing the total expense report amount to the requesters spending limit. For both fields, the currency code is passed in automatically based on the record passed into the query. There is no need for the user to select a currency code. The second condition in this example is comparing the total expense report amount to a fixed value of 10,000 United States dollars (USD). The user can click the ellipsis button (...) to specify the currency for the value that is entered into the right side of the condition. The currency code is still hidden on the left side of the condition because it is being calculated by the system in the parmAccountingCurrencyCode method.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-21
Developer Actions
To implement a new field that supports hierarchies in the Condition Editor, the developer must follow these steps. 1. Create a new class that implements the ExpressionHierarchyProvider base class. This class must implement the methods that are required to enable hierarchy support in the Condition Editor a. getDistance(): Returns the distance from the target node to the source node in a hierarchy. If a direct path from the source node to the target node does not exist then a nonzero value must be returned. b. getLookup(): Displays a lookup table that represents the hierarchy from which the user can select a node. The lookup table is typically the primary key table for this field in the foreign key table.
11-22
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Developer Actions
To implement a new field that supports hierarchies in the Condition Editor, the developer must follow these steps. 1. Create a new class that implements the ExpressionHierarchyProvider base class. This class must implement the methods that are required to enable hierarchy support in the Condition Editor a. getDistance(): Returns the distance from the target node to the source node in a hierarchy. If a direct path from the source node to the target node does not exist then a nonzero value must be returned. b. getLookup(): Displays a lookup table that represents the hierarchy from which the user can select a node. The lookup table is typically the primary key table for this field in the foreign key table. 2. Register the new class on the workflow document class that is used by decorating the class with the following attribute:
[WorkflowHierarchyProviderAttribute (classstr(MyHierarchyProviderImplementation), myTableId, myFieldId)]
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-23
11-24
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Challenge Yourself!
By using the information that is provided in the scenario, create a new workflow type for free text invoice lines called CustFreeTextInvoiceLineWorkflowTemplate that includes a new approval element. Make sure that you create a new status field on the lines of the free text invoice and that you enable work item queues for the free text invoice template. When you are finished, add the new free text invoice line workflow into the CustFreeTextInvoiceTemplate as a line-item workflow.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-25
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
11-28
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
3. Save the class. To update the completed method, follow these steps. 1. In the Compiler window, double-click the message that reads "Write code to execute once the workflow is completed." 2. In the Code Editor window for the completed() method enter the following code.
public void completed(WorkflowEventArgs _workflowEventArgs) { CustInvoiceLine custInvoiceLine; RecId custInvoiceLineRecId; custInvoiceLineRecId = _workflowEventArgs.parmWorkflowContext().parmRecId(); ttsBegin; select forUpdate custInvoiceLine where custInvoiceLine.RecId == custInvoiceLineRecId; custInvoiceLine.WorkflowStatus = CustFreeInvoiceWFApprovalStatus::Completed; custInvoiceLine.update(); ttsCommit; }
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
3. Save the class. 4. Close the Editor window. To update the main method of CustFTLineTemplateSubmitManager, follow these steps. 1. In the Code Editor window, select the Main method. 2. Enter the following code sample into the method.
public static void main(Args args) { CustFTLineTemplateSubmitManager CustFTLineTemplateSubmitManager; CustFTLineTemplateSubmitManager = new CustFTLineTemplateSubmitManager(); CustFTLineTemplateSubmitManager.submit(args); }
3. 4. 5. 6.
Save the class. Close the Code Editor window. Close the Compiler output window. Drag all of the objects from the Project CustFTLineTemplateWFType window into the Project WorkflowWorkshopLab window. 7. Close the Project CustFTLineTemplateWFType window.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-31
3. Save the class. To update the completed method, follow these steps. 1. In the Compiler window, double-click the message that reads "Write code to execute once the workflow is completed." 2. In the Code Editor window for the completed() method, enter the following code.
public void completed(WorkflowElementEventArgs _workflowElementEventArgs) { CustInvoiceLine custInvoiceLine; RecId custInvoiceLineRecId; custInvoiceLineRecId = _workflowElementEventArgs.parmWorkflowContext().parmRecId() ; ttsBegin; select forUpdate custInvoiceLine where custInvoiceLine.RecId == custInvoiceLineRecId; custInvoiceLine.WorkflowStatus = CustFreeInvoiceWFApprovalStatus::Completed; custInvoiceLine.update(); ttsCommit; }
11-32
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
3. Save the class. To update the returned method, follow these steps. 1. In the Compiler window, double-click the message that reads "Write code to execute once the workflow is returned." 2. In the Code Editor window for the returned() method, enter the following code.
public void returned(WorkflowElementEventArgs _workflowElementEventArgs) { CustInvoiceLine custInvoiceLine; RecId custInvoiceLineRecId; custInvoiceLineRecId = _workflowElementEventArgs.parmWorkflowContext().parmRecId() ; ttsBegin; select forUpdate custInvoiceLine where custInvoiceLine.RecId == custInvoiceLineRecId; custInvoiceLine.WorkflowStatus = CustFreeInvoiceWFApprovalStatus::Rejected; custInvoiceLine.update(); ttsCommit; }
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-33
3. Save the class. To update the class declaration, follow these steps. 1. In the FreeTextLineApprovalApprovalElement project, expand the FreeTextLineApprovalEventHandler class. 2. Double-click the classDeclartion. 3. In the Code Editor window for the classDeclaration enter the following code.
class FreeTextLineApprovalEventHandler implements WorkflowElementCanceledEventHandler, WorkflowElemChangeRequestedEventHandler, WorkflowElementCompletedEventHandler, WorkflowElementReturnedEventHandler, WorkflowElementStartedEventHandler { }
11-34
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-35
11-36
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Summary
Workflow in Microsoft Dynamics AX 2012 supports many new advanced features. The line-item workflow types are used to create a workflow for data that has a header and line relationship. Additionally, the workflow provider framework gives developers the flexibility to assign workflow elements to participants, queues, and users in a hierarchical structure. This chapter also reviewed the classes and attributes that can be called and extended by the developer to present currency and hierarchy type fields in the Condition Editor.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-37
11-38
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
4. Describe why you would set the EnableLineItemWaitSelection to Yes on a line-item workflow.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-39
2.
3.
11-40
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
Solutions
Test Your Knowledge
1. Put the following steps for developing a new work item queue in order: Step: 8 6 5 3 7 : Add the menu item on the main menu. : Create a new menu item. : Create a new query. : Override the mapFields() method. : Set the query property on the menu item.
4 : Set the WorkItemsCreatedEventHandler property on the approval or task element. 2 : Create a new class that extends WorkflowQueueCreatedEventHandler. 1 : Add the WorkflowDocIsQueueEnabledAttribute attribute to the workflow document. 2. Categorize the following items: d 1. Used to provide a specific end item, when a particular starting item is provided. a 2. Used to determine a specific due date for a task or approval based on a specified start date. b 3. Used to provide a list of users from any abstraction, such as a user group. c 4. Used to provide a list of users from a work item queue that is configured in the Home module. a. Due Date Provider b. Participant Provider c. Queue Provider d. Hierarchy Provider
3. Describe the difference between the getDistance() and getLookup() method in a class that implements the ExpressionHierarchyProvider class. MODEL ANSWER: getDistance(): Returns the distance from the target node to the source node in a hierarchy. If a direct path from the source node to the target node does not exist then a nonzero value must be returned. getLookup(): Displays a lookup table that represents the hierarchy from which the user can select a node. The lookup table is typically the primary key table for this field in the foreign key table.
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement
11-41
11-42
Microsoft Official Training Materials for Microsoft Dynamics Your use of this content is subject to your current services agreement