If you send out an Approval from within a model-driven App, you probably want to see the Approval Result in Dataverse. In this post we continue where we left off in our Approval from inside a Business Process Flow. Let me give you some background on the various Approval Flows and how they work. Including a tip on how to keep your Cloud Flows clean.
This blog is part of a series about guiding users and teams through their work. I have previously blogged about replacing Process Dialogs with embedded canvas apps. We are now 2,5 years further so I would like to present my learnings. There are a ton of new features added to the platform which I would also like to explore. As I write more post on this subject I will add them to the list below.
- Task Groups help you guide work in Business Process Flow
- Set form fields required based on Business Process Flow Stage
- Prettify your Business Process Flow by adding a Code Component
- Get Approval from inside your Business Process Flow
- Add Model App record link to an Approval Item Link
- Capture the Power Automate Approval result into Dataverse
Expanding the Case BPF
We are currently still working the Case of a broken screen. We are dealing with a loyal customer, so we asked Approval of our manager to immediately replace the screen. He either gives Approval to do so, or he does not. We want to capture his answer within our system so we can continue working the Case.
We prepared our data model already for this as seen in my first post about Approvals. I want to fill in the fields Approval result with the result of the Approval. And as our manager might type a comment in his response, I want to capture this in the Approver comment field.
Types of approval
There are several types of Approvals you can send. The “Approve / Reject” options will send out the standard Approval with only these 2 options. If you go for the “Custom Responses” you can choose your own set of options which an Approver can choose from. Depending on the second part of the available options the cloud flow continues on a different time. If you select in the category “Everyone must approve / Wait for all responses” the cloud flow will continue after everyone in the “Assigned to” list has responded. If you select “First to respond / Wait for one response” the flow will continue immediately after 1 response.
In our scenario we use the “Approve / Reject – First to respond” option. Remember to tweak your capture based on your own requirements. So after our manager responds to the Approval the cloud flow continues and we get the feedback from the manager. We want to save that feedback to the Case record we are working on. We add a condition based on the response as you can see in the overview below.
The condition however requires some expression to make your flow cleaner. As the Approval mechanism can contain multiple responses we will take the first of those responses. This will make sure we do not get an unwanted ‘For each’ inside our Cloud Flow. That helps a lot in readability of our Flow.
Now let’s get our Approval result in Dataverse
Inside the two branches of the condition we choose the “Update record” action in Dataverse. Select the Table Cases and the Row ID is the ID we get from the parameters of our trigger “When a flow step is executed”, the “BPF Flow Stage Id”. We set the “Approval step done?” to “Yes” and the “Approval result” to “Approved”. Of course if we are in the other branch we set the “Approval result” to “Rejected”.
In the field “Approver comment” we can add the comment our manager added “Responses Comment”. Again we need to specify that we want the first of the Approval responses to avoid a “For each”. Sadly if we do that we can no longer select the “Responses comment” from the Dynamic Content menu to help with our expression. We must type out the following code:
Tip: What I like to do is create a dummy “Compose” action. In this action I can select the attribute I want and use the “Peek Code” option to find out what the technical name is. This name I can then use in the expression I am actually working on.
That’s it, we are done! We have now saved the result and comment of the Approval to our record. See the gif below to see this in action.
If you think I am done with explaining my tips for Approvals inside a BPF now, you are mistaken! Yes we have created an Approval, added the record link to it and now captured the result, but I want to do one more thing! Automatically update the Business Process Flow Stage depending on the outcome of the Approval. But that is for a next post.