Capture the Power Automate Approval result into Dataverse

Shows an animated gif where the result and the comment of the Approval is saved to the Case record

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.

  1. Task Groups help you guide work in Business Process Flow
  2. Set form fields required based on Business Process Flow Stage
  3. Prettify your Business Process Flow by adding a Code Component
  4. Get Approval from inside your Business Process Flow
  5. Add Model App record link to an Approval Item Link
  6. 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.

Shows our case form highlighting the Approval result field and the Approver comment field we want to update
Form with the fields we want to update

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.

Shows the Approval inside the Approval app. Highlighting the comment field we want to eventually capture in our record.
Comment of the approval

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.

Shows the 4 different Approval types. Approve / Reject - Everyone must approve, Approve / Reject - First to respond, Custom Responses - Wait for all responses, Custom Responses - Wait for one response.
Types of Approval

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.

Shows an overview of the steps after waiting for approval. After a response have been given the flow splits in 2 paths based. 1 for approved, 1 for rejected. Both paths will update the result of the approval with the corresponding result.
Approval Response Overview

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.

first(outputs('Start_and_wait_for_an_approval')?['body/responses'])?['approverResponse']

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”.

Shows the Dataverse action "Update Record". Where the table is the Case we are working on. The column Approval Result gets updated to Approved and the Approver comment is filled with the response of the approval.
Update the Case Status and Approval Comment

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:

first(outputs('Start_and_wait_for_an_approval')?['body/responses'])?['comments']

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.

Shows an animated gif where the result and the comment of the Approval is saved to the Case record
Approval response saved to the Case record

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.

Leave a Reply

Your email address will not be published.