Power Automate: Send a Case Closure Survey

I was helping a member of the Power Platform community resolve an issue they were having, and I have been able to resolve the requirement with the following solution.

The Requirement

When a case is resolved within Dynamics 365, a Forms Pro survey should be sent to the customer to allow them to provide feedback. When the response is received, the feedback should be logged against the case.

Solution Overview

To deliver a solution to the requirement, I have created two Power Automate flows. One of which sends the initial survey to the customer and a second to tie the response back to the original case.

In addition to this, I also created a custom variable on the Forms Pro survey that can be used to find the original case when the response is received.

Forms Pro Setup

You set up the survey within Forms Pro as you would any other survey the only change that was made here was to create a variable for CaseID.

Flow 1 – Send Survey on Case Closure

The next piece of the puzzle was to create a Flow that sends out a survey to the customer when their case is marked as resolved.

Step 1 – When a Record is Created

The first step in the Flow is the trigger action which executes when a record is updated in the CDS. In this case the update of the Case record.

Under the advanced options, an additional attribute filter is added so that the trigger only considers updates to the statuscode filed on the case entity.

Step 2 – Check Condition

The next step is to check if the statuscode has been updated to resolved in this case, value 5.

Step 3 – Check Condition

The next section of the Flow follows the yes branch of the previous condition. There is no need for anything in the no condition. I have created a second check condition to check if the customer against the case is an account or contact. The only reason this was required as the method of getting the email address to send the survey to is different depending on the customer type on the case.

The following steps are duplicated in both the Yes and No branches. The only difference is that in the Yes branch it queries the account for the email address and in the No branch it queries the contact.

Step 4 – Get Record

The next step is to get the customer record to give you access to the email address in the next step.

Step 5 – Send Survey

This step is where the survey is sent to the customer’s email address.

In this step, you select the Survey and Email template that you created in Forms Pro.

As you can see the new variable that you also create is available to be populated.

I have chosen to populate this with the case number as I am also using it in my survey template. If you do not require to use this, you could use the GUID here.

Download

Flow 2 – Associate the Response with the Case

The other Flow triggers on the creation of a Forms Pro Survey response and creates a note against the case that the survey was sent from.

Step 1 – When a record is created

The trigger action is upon the creation of a Forms Pro Survey Response.

Step 2 and 3 – Initialise Variables

We now need to initialise two variables that we can utilise further down in the Flow. The first one is the ResponseID this is the identifier of the specific survey response.

The second is a variable to store the Originating CaseIdentifier.

Step 4 – Set Variable

The first variable that we have to set in the Flow is the Response ID; this will be used later to get the full response details.

This is set using the following expression:

@{triggerOutputs()?['body/msfp_sourceresponseidentifier']}

Step 5 – Parse Response JSON

We need to parse the response that we get from the survey to split the JSON up into component parts. We use the Parse JSON function to achieve this.

From the Forms Pro Survey Response, we need to parse the msfp_embedcontextparameters attribute. We can access this using the following expression:

@{triggerOutputs()?['body/msfp_embedcontextparameters']}

Step 6 – List Record

To create a note against the correct case, we need to find the case with the correct Case ID that has been passed over from the Form Pro Survey Response. This will be now available from the parsed JSON we created in the previous step.

In order to return only the relevant case, we can use the following filter query:

ticketnumber eq '@{body('Parse_JSON')?['PipeData']?['CaseID']}'

Step 6 – Apply to Each

As we have used the list records function, it is necessary to use an apply to each as the list records function has the possibility of returning multiple results.

Step 6A – Get Response Details

In order to get the full response details, including the questions and answers from the survey, we have to retrieve the full response using the Get response details function.

We have to set the specific survey that we wish to query and pass in the response ID. As we set this as a variable, we have access to it within the dynamics content.

Step 6B – Set Variable

We now need to set our second variable, which is the CaseID; this will allow us to append the note to the correct case record.

We can get the incidentid which is the unique reference for the case using the following expression:

@{items('Apply_to_each')?['incidentid']}

Step 6C – Create Record

Now that we have all the information that we require, we can go ahead and create a note. In this example, I have chosen to use the note entity, but you could create a custom entity to store this if you prefer.

We can, at this point, select what information we wish to populate from the response into the description. You can access this from the dynamic content.

The regarding field also has to be populated, and we have used the variable that we set in step 6B.

Download Flows

Share

You may also like...

Leave a Reply