Problem statement: It is quite frequent in workflow in Dynamics AX that one would like to notify users when certain approvals have occurred, tasks have been completed or when errors occur. This is pretty easy to accomplish out of the box with Dynamics AX by using the notifications on approvals, tasks or on the workflow as a whole. However the options are pretty limited and not very dynamic (especially in AX 2009) and up until AX2012 you have only really been allowed to assign to specific users (i.e. by user id). This means that it is very difficult to accomplish complex notifications such as notify the following people when a document has been approved: Document Creator, Project Manager for the document’s project and all users assigned to the “Accountants” security role in AX.
AX 2012 however has now allowed you the ability to make use of “Participant Providers” as an assignment option in notifications.
This means that you can create a Custom “notification” participant provider for your system that can resolve any number of personalised lists of users as above.
For example we created a particpant provider with a couple these lists. In our custom participant provider we returned a unique token per list e.g. “Originator, Project Manager, Requester and CEO” and “Originator, Project Manager, Financial Manager and CEO”.
In the resolve method of the participant provider we then retrieved the workflow document out of the workflow context object and returned the “Created by” user, looked up the project on the document and returned the associated Project manager and finally looked up the Financial Manager and CEO from a custom parameters table in AX and returned them as well.
The actual creation of a custom participant provider is beyond the scope of this article but you can find some more resources over here:
I hope this sparks some thought and is useful to some:
Inspired by: https://community.dynamics.com/ax/f/33/t/155436.aspx
A question that has come across on a number of occassions on the Dynamics Community forum is how can one allow the creator of a document to select an approver to approve the document. We did do a variation on this request for a client a couple of years ago, so here is one way to do it.
1. Create a custom field to store the approver on the record you are workflowing
2. Allow the user to populate this field (either directly on the record’s form, or via a pop-up request) on submission.
3. Create a custom participant provider that can resolve the user selected in #2
4. Modify your configuration to use this participant provider.
For this example I will make use of the PurchReqTable and its workflows
1. Create Custom Approver field
- Open the AOT, Data Dictionary, expand Tables, locate PurchReqTable. Expand the node and expand the fields node.
- Right Click on fields, click new -> String
- Rename your field (e.g. ChosenApprover) and provide a suitable Label
2. Allow the user to populate this field
Option A – Allow modification directly on the form:
- Open the AOT, expand the forms node, locate and expand the PurchReqTable node.
- Right click on data sources, click “open in new window”
- Expand the PurchReqTable datasource, expand the fields node
- Drag the “Chosen Approver” field to a relevant place on your form E.G. Designs->Design->Tabl->TabPageDetails->TabDetails->TabPageheader->TabHeader->TabPageHeaderGeneral->HeaderAdministration
- Locate the Class behind your workflow’s Submit button. E.G. PurchReqWorkflow.
- Before the code line “if (ret && purchReqWorkflow.dialogOk())’ add code to prompt the submitter to enter a user.
- Save the selected user to the PurchReqTable
3. Create a custom participant provider to resolve the ChosenApprover
- Open the AOT, right click on Classes, click “New Class”
- Rename Your class to “ChosenApproverParticipantProvider”
- Edit the class declarationand implement the “WorkflowParticipantProvider” interface
E.g. class ChosenApproverParticipantProvider implements WorkflowParticipantProvider
- Create a new method called “getParticipantToken” with the following code to present a single resolution option to the users…
public WorkflowParticipantTokenList getParticipantTokens()
WorkflowParticipantTokenList tokens = WorkflowParticipantTokenList::construct();
tokens.add(“CHOSENAPPROVER”, “User selected Approver”);
- Create a new method to resolve the token above called “resolve” with the following code (this code assumes that the provider will only be used from a purchase requisition and will not have resolution options other than “chosenApprover”, also it assumes that all requisitions will have the ChosenApprover field filled in:
public WorkflowUserList resolve(WorkflowContext _context,
WorkflowUserList userList = WorkflowUserList::construct(); //Retrieve the requisition from the workflow context
purchReqTable = PurchReqTable::find(_context.parmRecId());
userList.add(PurchReqTable.ChosenApprover); return userList;
- Save your class.
- Expand the Workflow node in the AOT, expand “providers”, right click on “participantProviders” and click “New Participant Assignment Provider”
- Rename the Provider to ChosenApproverParticipantProvider (similar to your class name)
- Right click on the provider, click properties.
- Provide a suitable label for the provider e.g. “Chosen approver provider”
- If your record is a cross company table select AssociationType of “Global”
- Choose “No” under “available for all workflow types” as this provider assumes that a PurchaseRequisition is being used.
- Under “ProviderClass” enter the name of your class created above. “ChosenApproverParticipantProvider”
- Associate your provider with the PurchReqWorkflow type: On expand your “ChosenApproverParticipantProvider” AOT node, right click on “workflow types”, click “new workflow type”. Right click on the newly created node, click properties, select the relevant workflow type under the “workflowType” Option. E.G. PurchReqReview
- Save the ParticipantProvider.
4. Modify your configuration to use this participant provider.
- Perform a CIL compile and close and open AX client for your changes to take effect.
- Navigate to your workflow configuration and click “edit”. E.G. Procurement and Sourcing -> Setup -> Procurement and sourcing workflows -> Select PurchReqReview configuration.
- Locate the node that you would like to assign to your Chosen User. Click assignment in the toolbar.
- On the assignment type tab, select Participant
- Click on the “Role Based” tab.
- Under type of participant select “Chosen Approver Provider”
- Under Participant select “User selected Approver”
- Save and close your workflow
- Ensure you activate the workflow version you just created!
All done! Test and enjoy!