*** NOTE: ALL INFORMATION IS ACCURATE AT DATE OF PUBLISHING ***

I’ve written so much about variables in Forms Pro and what you can do with them. After a chat with Welly Lee, Head of Product for Forms Pro at Microsoft, he shared yet another way we can use variables to create personalised surveys, and pass hidden variables back through survey responses. In this post, we look at how you can share a direct link to a survey, which would typically mean no personalisation is available. However, by appending variables to the end of the survey URL, we have so many options available to us. Check this out!

For this scenario, we have an online event people are attending. There are twenty different sessions going on throughout the day. Rather than have a different survey for each session, we want to have one survey, gather all of the responses, and know which session it is that the response relates to. The first thing we need to do is set up a new variable. In this example, it’s called SessionID.

We then need to add a question to the survey which will be kept hidden. This will be used to populate the Session ID variable back in as the answer at a later stage in the process.

You can then also use the variable in the survey itself.

In order to pass the SessionID variable through into the survey, we need to append it to the end of the Survey URL. So, when clicking on Send Survey and getting the URL, we can add &ctx= and then add a variable combined with a value. Below we can see the SessionID variable used, then Forms Pro Level One passed as the value for the session. The value would then be changed for each of the sessions at the event.

https://forms.office.com/FormsPro/Pages/ResponsePage.aspx?id=sZzdL-71VU-9jqfEAukn4L4m8nL7gGRPptWJgekdXoVUMlZOMVg3SlFPQk8zNloxSEhOVzU0R1pOTC4u&ctx={"SessionID":"Forms Pro Level One"}

Multiple values can also be passed using this format and keeping the variables and values in pairs.

&ctx={"<Var1>":"<Value1> ","<Var2>":"<Value2>"}

When viewing the survey, we can see the value for the SessionID variable is displayed. This is great, and a nice way to use it on the survey, but what we really want is to get that sessionID value back into the hidden question as a response.

To pass the value back through, we need to use Power Automate and set up a flow. Our first step is a trigger from the CDS connector when a survey response is received. Be sure to set a trigger condition so it only runs on the survey you want it to. You can follow this article to see how you can achieve this. Next, add a Parse JSON step and add the Context Data value as the Content, and add the Context Data schema that can be found on a response. You will need to complete the survey once in order to get this. If you have access to CDS you can follow some steps in this blog to figure out how to get it, and if you don’t have access to CDS you can follow this blog.

Now we need to find the hidden question we added to the survey. For this, we will use the List records action from the CDS connector. Our filter query is searching for the question that has the same name as our hidden question (Session ID in this example) and also where it equals the same source survey identifier as the survey response that was received.

msfp_questiontext eq 'Session ID' and msfp_sourcesurveyidentifier eq '@{triggerOutputs()?['body/msfp_sourcesurveyidentifier']}'

Our final step of the flow is to create a new question response for the Session ID question and link it back to the survey response we received. We need to fill out the following fields. The SessionID from the Parse JSON step will go into the Name, Key phrases and Response fields. The Source response identifier and the Source survey identifier will be pulled from the values from the initial trigger step. We can set the Owner as the same Owner of the survey response (making sure to set the Owner Type), and the Survey Response must be the Activity id from the initial trigger step. There are two expressions needed. First, one for the Source question identifier. This gets the source question identifier from the question pulled back in the previous List records step:

@{first(body('List_records')?['value'])['msfp_sourcequestionidentifier']}

Then, for the Question field, we use this expression. This gets the question id from the question pulled back in the previous List records step.

@{first(body('List_records')?['value'])['msfp_questionid']}

Now if we go to Forms Pro and look at the responses, we can Export all of them to Excel (or we could view in CDS if desired).

The Session ID field has been populated so we can see exactly which session the feedback has been provided for. 🙂

Want to just watch how to do this? Check out the video: https://youtu.be/7RPMGjaP1EU


Check out the latest post:
Part 4 - Creating Additional Filtered Views Of Website Data


This is just 1 of 207 articles. You can browse through all of them by going to the main blog page, or navigate through different categories to find more content you are interested in. You can also subscribe and get new blog posts emailed to you directly.


2 thoughts on “Passing Variables Through The Forms Pro Survey URL

  1. This really helps! Thank you for the great post.
    One question, if I pass more than one variable, can I insert all of them to response database with one flow, or I have to create flow for each variable?

    1. Hi Archates, you can do it all in one flow, just do a series of action steps to do this multiple times.

Leave a Reply

Your email address will not be published. Required fields are marked *