Microsoft Dynamics AX provides workflow functionality that you can use to ensure that documents are processed and approved in a consistent and efficient manner.
A workflow represents a business process. A workflow defines how a business document flows through the system by indicating who must process and approve it.
A workflow represents a business process. A workflow defines how a business document flows through the system by indicating who must process and approve it.
Creating Workflow in AX 2012
- Configure how the workflow engine is executed on a server.
- Specify which application module a workflow is applicable to using a workflow category.
- Link tables to workflows using a query.
- Create a new workflow type.
- Apply a workflow to a form.
- Define what happens when the workflow is approved or denied.
- Create Event Handlers and apply them to a workflow.
- Configure a workflow.
In Microsoft Dynamics AX, you define a workflow by creating a workflow type to base the workflow on. In this walkthrough, you will create a workflow type in the AOT that you can add approvals and tasks to.
A workflow type defines information about the following:
- Which document is being used with the workflow. The workflow document exposes calculated fields and identifies the query that exposes data fields for the workflow.
- Tasks, automated tasks, and approvals that can be configured by the end user.
- Workflow categories used for assigning a workflow type to a specific module.
- Menu items and event handlers.
This walkthrough illustrates the following tasks:
- Creating a query for a workflow.
- Creating a workflow category.
- Creating a workflow type in the AOT.
- Adding code to the SubmitManager class.
To Create a Query for a Workflow
- In the AOT, right-click the Queries node, and then select New Query. A query group displays under the Queries node.
- Right-click the new query, click Rename, and then enter MyQuery.
- Expand the new query, right-click the Data Sources node, and then click New Data Source. A data source group displays under the Data Sources node.
- Right-click the new data source group and then click Properties.
- In the Properties sheet, set the Table property to CustTable.
- Expand the CusTable_1 data source, and select the Fields node. In the Properties sheet, set the Dynamic property to Yes.Note :-
By setting the Dynamic property to Yes, all data fields in the CustTable table are exposed for workflow conditions. To remove data fields, set the Dynamic property on the Fields node of the data source to No. Expand the Fields node, right-click a field, and then click Delete. If the query is not saved, the Delete command is not available.
- In the AOT, right-click MyQuery, and then click Save.
After a Microsoft Dynamics AX query is created, you must decide which category the workflow will be part of. We recommend that you choose an existing workflow category. If no category is appropriate, you can create your own.
To Create a Workflow Category
- In the AOT, expand the Workflow node.
- Right-click the Workflow Categories node, and then select New Workflow Category. A new workflow category group displays under the Workflow Categories node.
- Right-click the new workflow category and then click Properties.
- In the Properties sheet, set the following properties:PropertyValueNameMyWorkflowCategoryModuleCustomer
- In the AOT, right-click MyWorkflowCategory, and then click Save.
After a workflow category is created, you are ready to create the workflow type.
To Create a Workflow Type in the AOT
- In the AOT, expand the Workflow node.
- Right-click the Workflow Types node, and then click Add-Ins > Workflow type wizard. The Workflow wizard is displayed. This wizard will help you create a new workflow type.
- Click Next.
- Set the following values for the wizard.ValueInputNameEnter MyWorkflowType.CategoryChoose MyWorkflowCategory, which is the category that you created.QueryChoose MyQuery, which is the query that you created.Document menu itemChoose CustTable, which points to the main form for displaying customer data.Document web menu itemChoose EPCustTableInfo, which points to the main page for displaying customer data in Enterprise Portal.
- Click Both to generate menu items for both the Microsoft Dynamics AX client and Enterprise Portal.
- Click Next. A list of all of the resources that will be created for the workflow type is displayed.
- Click Finish to create the resources. The wizard will create classes, menu items, web menu items, the workflow type, and a project that contains all of the items.
- A dialog box will be displayed that indicates the status. Click OK. The project that contains the workflow type resources is displayed.
After the workflow type is created, you will add code for the workflow events. However, to simplify this walkthrough, you will not add code to any of the event handlers.
To enable end-users to submit a workflow document for approval, you will have to add code that is run when the user clicks Submit in Microsoft Dynamics AX. The main method in the SubmitManager class that was created by the Workflow wizard will run. This code will display a message in the user interface that indicates that the document was submitted to workflow.
To Add Code to the SubmitManager Class
- In the AOT, expand the Classes node.
- Locate the MyWorkflowTypeSubmitManager class. This was the class created by the Workflow wizard.
- Expand the MyWorkflowTypeSubmitManager class, and then double-click the main method. The Editor window opens.
- In the Editor window, insert the following code.
public static void main(Args args) { // Variable declaration. recId _recId = args.record().RecId; WorkflowCorrelationId _workflowCorrelationId; // Hardcoded type name workflowTypeName _workflowTypeName = workFlowTypeStr("MyWorkflowType"); // Initial note is the information that users enter when they // submit the document for workflow. WorkflowComment _initialNote = ""; WorkflowSubmitDialog workflowSubmitDialog; // Opens the submit to workflow dialog. workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration()); workflowSubmitDialog.run(); if (workflowSubmitDialog.parmIsClosedOK()) { _recId = args.record().RecId; // Get comments from the submit to workflow dialog. _initialNote = workflowSubmitDialog.parmWorkflowComment(); try { ttsbegin; // Activate the workflow. _workflowCorrelationId = Workflow::activateFromWorkflowType(_workflowTypeName, _recId, _initialNote, NoYes::No); // Send an Infolog message. info("Submitted to workflow."); ttscommit; } catch(exception::Error) { info("Error on workflow activation."); } } }
- Close the Editor window and then click Yes to save changes.
- Any time that you create or modify workflow code, you must regenerate the CIL code. In the AOT, right-click AOT, click Add-Ins, and then select Incremental CIL generation from X++.
After MySubmitToWorkflowClass is created, you can create an action menu item to bind this class to.
To Enable a Form for Workflow
- In the AOT, expand the Forms node.
- Expand the CustTable form, and then expand the Designs node.
- In the Designs node, right-click the Design child node, and then click Properties.
- In the Properties sheet, set the following properties.PropertyValueWorkflowEnabledYesWorkflowDataSourceCustTableNoteThis is the root data source specified in the query used for the Document property on the MyWorkfowType type. For more information, see Walkthrough: Creating a Workflow Type.WorkflowTypeMyWorkflowType
- In the AOT, right-click the CustTable form, and then click Save.
After the form is enabled for workflow, you will add a canSubmitToWorkflow method to the form. This method runs before the Submit button is enabled to verify that the workflow document is in a valid state to submit to workflow. When this method returns true, the Submit button is enabled. An alternative is to add the canSubmitToWorkflowmethod to the main table for the form. This allows both the Microsoft Dynamics AX client and Enterprise Portal to share the same logic to determine whether workflow is enabled.
Note |
---|
If there are no records in the data source and the canSubmitToWorkflow method returns true, an exception is thrown. Therefore, you should programatically check for a record when you evaluate the state of the workflow.
|
To Create a Method to Indicate Whether the Current Document can be Submitted to Workflow
- In the AOT, expand the CustTable form, right-click the Methods node and then point to Override method. Click canSubmitToWorkflow.
- A method node named canSubmitToWorkflow displays under the Methods node and the Editor window opens.
- In the Editor window, enter the following code to enable the Submit button on the form for workflow.
public boolean canSubmitToWorkflow() { // ToDo This method always returns true and the Submit // button will always be displayed on the form. Enter code // here to only return true when the document is NotSubmitted. // Also, add code to check if a record exists in the data source. return true; }
- Close the Editor window and then click Yes to save changes.
Now that the form is enabled for workflow, you must create a workflow configuration to display the Submit button on the workflow toolbar.
To Create a Configuration
- In Microsoft Dynamics AX, click Accounts receivable > Setup > Accounts receivable workflows. The Accounts receivable workflows list is displayed.
- In the Accounts receivable workflows list, click New. The Create workflow form is displayed.
- On the Create workflow form, select MyWorkflowType, and then click Create workflow. The workflow configuration form is displayed.
- In the action pane, click Properties. The Properties form is displayed.
- In the Properties form, click Basic Settings. In the Submission instructions text box, enter My workflow submit instructions., and then click Close.
- In the MyWorkflowType form, create a simple workflow by dragging a Conditional decision onto the workflow in between the Start and End nodes. Drag a line from the Start node to the Conditional decision 1 node. Then, drag a line from the True output of the Conditional Decision 1 node to the End node. Finally, drag a line from the False output of the Conditional decision 1 node to the End node.
Tip You may need to scroll down in the workflow designer form to see the End node. - Right-click Conditional decision 1, and select Properties. The Properties form opens.
- In the Conditional tab, click Add condition, and then enter Where Customers.Account number contains value 0.
- Click Close.
- In the workflow designer form, click Save and close. Enter Workflow Walkthrough in the Version notes field and click OK.
- The Activate workflow – MyWorkflowType form appears. In the Activate workflow – MyWorkflowType form, select Activate the new version, and then click OK.
- Display the Accounts receivable area page.
- Click Customers > All customers.
- Double-click one of the customers in the list. The Customers form is displayed.
- The workflow toolbar is displayed at the top of the CustTable form. Click the View Workflow Instructions icon on the workflow toolbar to display the submission instructions that you created in this walkthrough.
- Click MyWorkflowTypeSubmitMenuItem, which is the menu item that you created to submit the customer to workflow. Supply a submission comment and then clickMyWorkflowTypeSubmitMenuItem to see the submitted to workflow Infolog message.
Source :-https://msdn.microsoft.com/EN-US/library/cc641259.aspx
could you please provide me .xpo file project for that workflow
ReplyDeleteThanks for the blog article.Thanks Again. Keep writing.
ReplyDeletebest salesforce online training
salesforce online training from india