In D365 PSA, we do not get the multi level approval functionality in the OOB time/expense approval process.
But I know some of our customers need to have multi level approvals for some of their daytoday business process(specially for expense approval).
When we click the approve button in project approval records(Either using the home ribbon button or form ribbon button), it invokes below OOB msdyn actions accordingly.
Expense approval
- msdyn_ExpenseEntriesPendingApproval
- msdyn_ExpenseEntriesApprove
Time Approval
- msdyn_TimeEntriesPendingApproval
- msdyn_TimeEntriesApprove
Below is my solution for extending the OOB project approval functionality to enable multi level approvals for PSA. In this article my main intention is just to give you an idea about how to extend above actions to implement multi level approvals. Hence you can use that concept and implement your own extended solution.
Solution:
- Create your own setting entity to configure and enable multi level approval("Approval Rule" is my entity).
- Create your own entity to configure approval hierarchy("Approval Hierarchy" is my entity).
- Has a 1:N relationship with Approval Rule entity.
- Contains the approvers and the hierarchy.
- Create your own entity or add new fields to Project Approval entity to track your current approver and the status. (I prefer to use a new entity "Approval Tracking")
- Create a new plugin for post create event in Project Approval entity and create new approval tracking record/s accordingly.
- Create pre execute plugins accordingly for above mentioned msdyn actions and implement below logic.
- In Pending Approval action
- Remove the id/s form approval action unless it has passed through the hierarchy. (I have explain id removal process below under tips to remove ids form approval and the example.)
- In Approve action
- If the project approval record is not in the last approval stage according to the hierarchy, assign the project approval record to the next approver in the hierarchy.
- Update relevant Approval Tracking entity record with the current stage.
- Remove the id/s form approval action unless it has passed through the hierarchy. (I have explain id removal process below under tips to remove ids form approval and the example)
Tips to remove ids form approval :
- In expense approval actions, the entries for approval are passed to the actions as a string and the input parameter "ExpenseEntryIds" holds the value.
- In time approval actions, the entries for approval are passed to the actions as a string and the input parameter "TimeEntryIds" holds the value.
- From home ribbon button click, it sends all the selected record ids as a comma separated string and from form ribbon button click it just send the relevant record id as a string.
Example :
Step 1: Write a new plugin for msdyn_ExpenseEntriesApprove action.
// Get the entry ids to process from input parameters. var entryIdsToProcess = localContext.PluginExecutionContext.InputParameters["ExpenseEntryIds"].ToString(); // Implement your own method with custom logic to remove expense ids which are not in final stage of the approval process. var newEntryIdsToProcess = RemoveEntryIds(localContext, entryIdsToProcess); // Update ExpenseEntryIds with newEntryIdsToProcess. localContext.PluginExecutionContext.InputParameters["ExpenseEntryIds"] = entryIdsToProcess;
Step 2: Register your plugin for for the pre operation of msdyn_ExpenseEntriesApprove action.
I hope using above steps, you can implement your own, multi level approval solution for PSA.
If you face any issue while implementing, please add a comment or send me a direct message. I'm happy to help you.
If you face any issue while implementing, please add a comment or send me a direct message. I'm happy to help you.
Happy coding 😊
No comments:
Post a Comment