This article will cover step-by-step instructions on how to create a workflow approval flow in Power Automate which will trigger back the user response in Microsoft Dynamics 365.
Power Automate is a service that?helps you create automated workflows between your favorite apps and services to synchronize files, get notifications, collect data, and more. You might be thinking that there must be high-level coding involved. Well, I'm from a Finance background and if a layman like me can create a flow then you can also do it without knowing computer languages. You just need to completely understand the front-end of the application and develop some logic while creating the flow in Power automate.
Follow the steps mentioned below:
Step 1: Add a trigger "When a Business Event Occurs"
- Login into Power automate and click on the "Create" button.
- Now click on "Automated cloud flow".
- Enter the flow name as "Approval Flow".
- Search a trigger i.e. "When a Business Event Occurs".
- Select the "When a Business Event Occurs".
- Select the instance. In the drop-down, it will show you all the environments (e.g. stg, prod, dev). I have selected the Staging environment for testing purposes.
- Select "Workflow workitem" in the category. Whenever a workitem is assigned in Dynamics 365, it has a unique ID. So, in case there are multiple approvers there will be multiple workitems with a unique ID. Power automate will trigger each workitem (a separate business event).
- Select the business event from the drop-down. It will show you all the workflows configured in the environment. Select the relevant workflow ID by checking from the specific module workflow setups.
- Select the relevant "Legal Entity".
Step 2: Add "Parse JSON (Data Operation)"
- Click on the "Content" field and it will auto-populate "body". Select the body from the Dynamics content.
- Click on "Generate from Sample" and paste the schema. Log into Dynamics 365 to download the schema.
Navigation: System Administration > Setup > Business Events > Business Events Catalog
- Select the relevant "Workflow workitem" and cross-check the name as (i.e.Approve Purchase Order).
- Click on "Download schema" and a text file will be downloaded.
- Copy the schema from the file and now you have to paste it in the schema of Parse JSON.
- Click on "Generate from Sample" and paste the schema. Then, click on "Done".
Step 3: Add Finance & Operations "Execute Action"
- Select the instance same as Step 1.
- Select "WorkflowWorkitems-validate" in the action. The drop-down will show you multiple actions.
- Select "WorkflowWorkItemInstanceId" in the WorkflowWorkItemInstanceId field from the Dynamic content. All the Dynamic contents will be available once you click on the WorkflowWorkItemInstanceId field.
Step 4: Add "Condition" step
- Add a new condition control step to check the result of the validate action. The dynamic field won't provide the required output. Therefore, you must manually enter the following expression instead:?Body('Execute_action')?['value']. Then select?OK.
- Type "True" in the highlighted field.
- The condition control automatically creates two branches for?Yes/No?results.
- The next time that you open the workflow after saving it, you will notice that the expression has been updated so that it shows the?value?field as in the screenshot attached above.
Step 5: Add steps in the "If Yes"
- If the result of the validate step is "Yes", you must start a new Power Automate approval step. In the "Yes" container, select a new action that is named "Start and wait for an approval".
- In the approval type, select "Approve/Reject - first to respond" from the drop-down menu.
- In the Title field, select "WorkflowWorkitemsubject" from the Dynamic content. This is the subject of the email. It will fetch the Workitem subject from the workflow tool in Dynamics 365.
- In the Assigned to field, select "WorkflowUserEmail" from the Dynamic content. It will send an email to the user who has been assigned to approve.
- In the Details field, select "WorkflowStepInstruction". This is the body of the email. It will fetch the Workitem instruction from the workflow tool in Dynamics 365.
- Select "Link to the web" from the Dynamic content. This is the direct link of the PO in Dynamics 365.
- In the description field, provide any desired description of the link.
Note: Read my other article (Workflows with Email Configuration - Step 3) to learn how to design a message in the workflow tool through placeholders.
- Next, you must complete the workflow approval by using the outcome of the approval step. Still, in the?Yes?container, add a new?"Finance and Operations Execute Action"?step.
- Select the instance.
- Select "WorkfowWorkItems-complete" in the action field.
- Select "WorkflowWorkItemInstanceId" in the WorkflowWorkItemInstanceId from Dynamics content.
- Select "Outcome" in the outcome field.
- In the comment field fill, (Response: "Responses Approvers Response" and Approver: "Responses Approver Name").
- Select "WorkitemOwner" in RunAsUser field.
- Once you select the output?"Responses"?as an input for the comment section, Power Automate automatically embeds your action in an?"Apply to each"?container as shown above.
Step 6: Add email step in the "If No"
If the result of the validate step is?No, an email must be sent to the user. This email notifies the user that a new task requires attention and that the user must sign in.
- Add "Send an email" action.
- Design the subject and body according to the business requirement.
- Now Save the flow and check the endpoint in Dynamics 365.
Step 7: Verify Endpoint in Dynamics 365
Navigation: System Administration > Setup > Business Events > Business Events Catalog
Now you can test the flow.
Outcome
The outcome of the flow above can be seen from the screenshot below, which contains an example of the e-mail that is received by an approver, once a user has submitted the work item.
Users can also approve/reject through Power Automate IOS/Android application.
Hope this article helped you. Feel free to share any feedback and share this article.
Software developer at Wai Technology
3 个月Thanks Ahmad for this Content , Can you tell me how to trigger this Workflow .
Finance Architect - D365 F&O at Hitachi Solutions America
4 个月This article is incredibly helpful! I can process the flow all the way through except I don't get an email sent to me when I go through the "Yes" path of the condition. No errors or warnings are present. I can approve the workflow through the Power Automate app and it works fine with D365 FO. Just no email being sent out. I even tried setting the notifications to Yes to see if that would change anything but no difference.
Sr. Technical Analyst ( Microsoft Certified Dynamics 365 Finance Functional Consultant )
1 年Thanks for the post. Created the flow for PO approvals but facing issue if the PO is recalled in Dynamics 365 . Recall is not updating in the power automate. How can we incorporate the recall option in D365.
Technical Consultant at Pavilion IT
1 年It was very helpful and thank you for posting so much, but I have a question for purchase order is there any chance we can add the purchase order lines to the email or teams notification?
Microsoft Dynamics 365 Finance and Operations Technical Consultant | Team Lead | Microsoft Certified Developer
1 年Really Helpful! Jug Jug Jeeyo