Tracking Opportunity Approvals

Last week I had an interesting requirement for one of my prospects. They wanted to track approvals for opportunity records in Dynamics 365 Sales. You’re probably going to say ‘That’s easy enough, just use Power Automate and create a flow with approvals but it was a tiny bit more complicated than that, which made me think this configuration would make an interesting topic to write about. I learned a lot while working on this, hopefully you will too! To elaborate, this wasn’t just kicking off an approval, as they also wanted their sales reps to be able to drill into the opportunity in Dynamics 365 and see approval information. Approval data they wanted to track was the date the approval was submitted, the status of the approval, when the approval was denied or approved and who the approver was. They also informed me that today they manage their approvals by using office 365 groups, where the approval email goes to a group of people. (this is very similar to email distribution groups) The members of these groups change very regularly and they stated they would like to continue to use office 365 groups to manage approvals. Sending approvals to a group of people vs one person is obviously a great way to implement this functionality; if one of the group members is on vacation or out sick, someone else can still pick up the approval.

Configuration

Dynamics 365 Entity

There are a couple of different things I need to set up here. The first thing I am going to do is build a custom entity called ‘Approvals’ where I can store the approval information. (I already have an approvals entity in my instance which is called WO Approvals instead.) I’ll configure this entity to be organization owned, since I don’t care if others see the approval information, but obviously you can choose to make this an owner-type of entity if you prefer. The fields I will add to this entity are:

  • Submission Date – Date
  • Submitted to – Single Line of Text
  • Approval Date – Date
  • Approver – Single Line of Text
  • Notes – Multiple Lines of Text
  • Opportunity – Lookup to opportunity entity

I also need to add an option set field to the opportunity entity, which I will use to trigger the flow. I’ll name the field ‘Approval Required’ (new_approvalrequired) and the field has two values; Yes (1) and No (2). If this field is set to Yes (value=1) I want my flow to run. Keep in mind I’m building a solution for a prospect demo, which is why I’m using this option set field as the trigger. A real life example could be triggering based on the opportunity’s estimated revenue amount or the type of account the opportunity belongs to, etc.

Exchange Office 365 Group

The next thing I need to do is create an office 365 group in exchange. This is a really simple task, but let me explain the steps on how to do this in case you haven’t done this before. Navigate to https://admin.microsoft.com/ and expand the admin centers. Open the Exchange admin center. On the dashboard, under recipients, click on groups. Click on +New Office 365 group. You’ll need to enter a group name, email address and some additional information. I called my group ‘approvals’ and also used this as the email address. (approvals@yourcompany.com)

Keep in mind that it doesn’t really matter what the email address of the group is, because we’re not going to send the approval to the group email address. That would be a nice and easy thing to do, but I don’t believe this is possible in Power Automate today, at least when I was testing this, the approval email never arrived in the team members’ inbox. Instead of using the group’s email address, I’m going to use power automate to get the group members’ email addresses, and send the approval email to each individual member. After you save the group, make sure you add a few members to the group.

Power Automate Flow

Now that I have my pre-setup done, lets get to the fun stuff and start building out the flow in Power Automate! Navigate to https://us.flow.microsoft.com/. Make sure you are in the correct environment; the environment you’re in is listed on the top right next to the gear icon. If you’re not in the correct environment you can change the environment by clicking on the environment name and clicking on a different environment. I’m going to build my flow from within the context on a solution, which makes them portable, allowing me to move this flow to another tenant if I wanted to. I’m also doing this because this allows me to use the ‘CDS (current environment) connector, which gives me additional options that are not available when I use the ‘old’ CDS connector. The ‘current environment’ CDS connector is only available if you create your flow from within the context of a solution.

If you want to learn more about this, you can read this article Sara Lagerquist wrote on this topic.

On the left side, click on ‘solutions’, then click ‘+New Solution’ on the top command bar to create a new solution. I created an unmanaged solution and called it ‘Opportunity Approval Flow’. After you save the solution, click on it to open. On the command bar on the top, click ‘+New’ and select ‘Flow’ from the list. This will open the flow configuration page where I’ll start by choosing my connector. I used the ‘When a record is created, updated or deleted-CDS (current environment)’ trigger.

For the trigger condition I select ‘update’, the entity is opportunities and the scope is organization. If you’ve used Workflows in Dynamics 365 before, this is the same scope you pick when creating workflows. In order to see additional options, you’ll need to click the blue ‘show advanced options’ link. You’ll see the ‘Run As’ option, which is also available in Dynamics 365 workflows. I picked to run the flow as the process owner. I also added a filter expression in the trigger, as I only want this flow to run if the approval required field equals yes, (the yes value in the option set has a value of 1) so my filter expression is ‘new_approvalrequired eq 1’.
Now I can move on with the next step! The first thing I want to do is create an approval record in Dynamics 365 and attach it to the opportunity so that the sales rep can see that there is an approval associated with this opportunity.
Click ‘+New Step’ and click ‘Create a new record(current environment)’. You might have to scroll all the way down before you see it, but make sure you’re picking the correct one. The entity name is ‘wo approvals’, and we want to tie it to the opportunity record that triggered the flow, so in the ‘opportunity(opportunities)’ field I need to set the entity name ‘/opportunities’ and the dynamic content (opportunity) in parenthesis. I also want to populate the submission date with the current date and time and I can do that by using an expression. Click in the ‘Submission date’ field, then click on the ‘Expression’ tab and type ‘Now’ in the expression box. Click ‘OK’ to enter the expression in the field.

In the next step I’m going to get the Office 365 group members belonging to the approval group I created earlier. The step is called ‘List group members’, and I am able to point to the correct group from the group id drop down field (Keep in mind you need to have access to this group in order to see it here) The next step is the ‘select’ step’ where I tell flow which data I want to capture from the ‘List Group Members’ step, which is the email addresses. Enter ‘value’ in the ‘from’ field, then click on the icon all the way on the right side of the ‘map’ field (switch to text mode). You should now see one column. Click your mouse in the field and select ‘mail’ under dynamic content. It took me a a bit of time to figure out the next step. I tried to send the approval to the output of the ‘select’ step, but I realized that the email addresses that are being returned are all mashed together with nothing separating them. Obviously you can’t send an email to multiple people that way, their email addresses need to be separated by a semicolumn. So after some help from the internet I found that I needed a ‘Join’ step in order to add the semi column between the office groups members’ email addresses. I select the ‘output’ from the previous step in the ‘from’ field, and enter a semi column in the ‘join with’ step.

Now that I have separated the email addresses with a semicolumn I can start the approval step! I select ‘Start and wait for an approval’ step and select ‘first to respond’ as the approval type. You can enter any information in the title field including information from the related opportunity. Enter ‘output’ (make sure it’s the output from the ‘join’ step) in the ‘assigned to’ field. If desired you can also add the item link. I didn’t find a good way to do this, so I opened up an opportunity record and copied everything except for the opportunity guid (right up to ‘=opportunity&id=’) next to that I enter the opportunity unique id from the dynamic content window, which now gives approvers a direct link to the opportunity they are about to approve/deny.
My next step is a condition where I have different actions depending on the approval outcome: If the opportunity is approved I want the flow to update the wo approval record in Dynamics 365 with the approval date, approver notes and name of the approver, but I also need to set the status to ‘approve’. If the outcome of the approval is denied, I need to update the same fields on the wo approvals record, but I need to set the status field to denied. An example of one or more additional steps are a notification email to the sales rep to let them know their opportunity was approved or denied, a second approval submission to senior leadership, etc.

I hope you enjoyed this post! Be sure to check in again next week for another post or subscribe here to never miss another post!

If you want to see me building the flow step by step, take a look at the video below!

Share this!

One Comment to Tracking Opportunity Approvals