cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
brock
Frequent Visitor

Pull MS Forms Question

 

How can I pull an MS Forms Question text with an expression?  I can pull the Answer text from the Get Response body with an expression (Filter null values from a Forms Array ). 

 

When I run a Flow test, the OUTPUTS of Get Response details has this info, but I don't know how to get at it. I am trying to do Select on the outputs on 

1 ACCEPTED SOLUTION

Accepted Solutions

@brock @Duri @Anonymous - I found a way to do this with the 'HTTP AD' connector pointing towards the forms domain.  I inspected the network traffic while browsing the forms website in order to find the right endpoint (same as the 'Forms' connector!) and which fields to query for (/questions)

When authenticating I chose the base and service 'https://forms.office.com':

snip_form_flow_httpad.JPG

Make sure you choose Invoke HTTP request

snip_form_flow_questions.JPG

And to make it re-usable:

 

/formapi/api/forms('@{concat(triggerBody()?['resourceData']?['formId'])}')?$expand=questions

 

^Paste this into the field, not the expression popup.

In the response, questions is an array of objects, each object is a question from the form and it's related properties - most not useful.  For each object the property 'id' will match the key for it's response used in the builtin forms connector.  Another property of that same object 'title' contains the question text as seen in the form. 

That should get the questions and id relationship you're looking for.

I did not need to act on any of the questions, just wanted to pull them for viewing in an email so this may not be useful from here on depending on usecase:

snip_form_flow_parse_and_var.JPG

The full schema I used:

 

{
    "type": "object",
    "properties": {
        "questions": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "title": {
                        "type": "string"
                    },
                    "order": {
                        "type": "integer"
                    },
                    "type": {
                        "type": "string"
                    },
                    "required": {
                        "type": "boolean"
                    },
                    "questionInfo": {
                        "type": "string"
                    },
                    "groupId": {},
                    "status": {
                        "type": "string"
                    },
                    "subtitle": {},
                    "allowMultipleValues": {},
                    "trackingId": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

 

A loop to tie questions and responses together:

snip_form_flow_foreach_if.JPG

For the apply to each, select 'questions' from dynamic content.  This should work but it may become obsolete if the api calls change.  You might have to test run the flow to kick the dynamic content to show up.

 

The first fx body(...) - this should pull the Response based on the id from the current question.  The goal is to verify it's not empty.

 

@{body('Get_response_details')?[items('Apply_to_each')?['id']]}

 

^Paste this into the field, not the expression popup.

The output of the compose action pipes into the conditional left-hand side as dynamic content
The right hand side should be the expression: 

 

string('')

 

Leaving the 'if yes' branch empty (meaning 'skip if there is no response to the given question')

I append to my string variable:

 

"@concat('<b>', items('Apply_to_each')?['title'], '</b>  ', body('Get_response_details')?[items('Apply_to_each')?['id']], '<br><br>')"

 

^Paste this into the field, not the expression popup.

Again - it depends on the usecase, for me this creates a string to nicely fit into emails where the questions are in bold and the response is not. I have two 'breaks' in there for line spacing for readability. 

Hopefully this makes sense

View solution in original post

25 REPLIES 25
AlanPs1
Resident Rockstar
Resident Rockstar

Hi @brock 

Are the questions your form the same all the time?

Using the model you linked to, if Q1 and Q2 were to output like the following:

Q1: Is this a form?
A1: Yes

Q2: How cool is this form?
A2: 7

 

Would that be what you are after? Just in plain text, and not dynamically accessing the actual questions?

 

Thanks, Alan

The questions in my form may change sometimes (it is a shared form).

 

I am not completely sure, but I think I am looking to "dynamically access the actual questions".

 

I want to at least avoid having to type in the question text in my expressions.  Of secondary importance is to be able to update the Questions in Forms without having to then modify the Flow experessions.

 

I would also be grateful for any partial solution to this...  plain text or otherwise     Robot Happy

Hi @brock ,

I am tring to work on a way to get the dynamic data as Flow displays it but in the "Get response details" action on a successful run. I haven't quite cracked that yet and it may not be possible but I am persevering.Capture-413.png

In the mean time, consider the expression below from the other post:

if(equals(not(empty(body('Get_response_details')?['r4b6e28cb8fa748dea068dc564271226e'])), true), concat('Q1: ', body('Get_response_details')?['r4b6e28cb8fa748dea068dc564271226e']), null)

This could become:

if(equals(not(empty(body('Get_response_details')?['r4b6e28cb8fa748dea068dc564271226e'])), true), concat('Date of Birth?:  ', body('Get_response_details')?['r4b6e28cb8fa748dea068dc564271226e']), null)

So basically changing "Q1: " to "Date of Birth?: "

This should get the job done and if I can find a way to get at the actual questions from the Form, I will post back.

 

If you have found my post helpful, please mark thumbs up.

Any other questions, just ask.

Thanks, Alan

@AlanPs1 

 

Yes, that is what I am doing now (putting the question text into the concat().

 

thanks for looking at this, I hope there is a way.

Hi Brock.
So, there is a way, it is an advanced hack though that involves editing the JSON on the connector and exposing internal properties. I have it working partly in my environment. Stick with what you have for now and I plan on posting a blog about the advanced method once I have it polished. I’ll let you know once I have the method complete and the post out there.

Thanks, Alan.

YYYYYYYY        YYYYYYYY    EEEEEEEEEEEEEEEEEE      SSSSSSSSSSS
YYYYYYYY        YYYYYYYY    EEEEEEEEEEEEEEEEEE     SSSSSSSSSSSSS
YYYYYYYY        YYYYYYYY    EEEEEEEEEEEEEEEEEE    SSSSSSSSSSSSSSS
YYYYYYYY        YYYYYYYY    EEEEEEEEEEEEEEEEEE    SSSSSSSS    SSS
 YYYYYYYY      YYYYYYYY     EEEEEEEE              SSSSSSSS
  YYYYYYYY    YYYYYYYY      EEEEEEEE              SSSSSSSS
   YYYYYYYY  YYYYYYYY       EEEEEEEEEEEEE          SSSSSSSS
    YYYYYYYYYYYYYYYY        EEEEEEEEEEEEE           SSSSSSSSSS
     YYYYYYYYYYYYYY         EEEEEEEEEEEEE            SSSSSSSSSS
      YYYYYYYYYYYY          EEEEEEEEEEEEE               SSSSSSSSS
       YYYYYYYYYY           EEEEEEEE                     SSSSSSSS
        YYYYYYYY            EEEEEEEE                     SSSSSSSS
        YYYYYYYY            EEEEEEEEEEEEEEEEE     SSS    SSSSSSSS
        YYYYYYYY            EEEEEEEEEEEEEEEEE     SSSSSSSSSSSSSSS
        YYYYYYYY            EEEEEEEEEEEEEEEEE      SSSSSSSSSSSSS
        YYYYYYYY            EEEEEEEEEEEEEEEEE       SSSSSSSSSSS
Anonymous
Not applicable

Hi @AlanPs1 ,

Do you have an update on this? I also need the questions, coming from the Form. It's a bit frustration, because I know the info is in there, but I can't access it.

Kind regards,

Thye

Hi @AlanPs1 

 

 I have browsed a lot and could not find a solution for this. Have you managed to resolve this?

 

I would be very grateful if you shared your workaround - it would help me a lot.

 

I will have multiple questionnaires/forms with multiple sections (some filled, some not) - Each single response (which is filled) will make one record (in a database) with an attribute from the question name.

 

But instead of GUID response form, I need the actual question name (to map it with the proper attribute) - as the questions will be changing over time.

 

Thanks a lot!

 

 

I never found a way to what you want. I ended up putting each question response into a Compose and then building a question/answer table by explicitly stating the question text in my expression. It's problematic when the question text changes or I make a mistake.

@brock @Duri @Anonymous - I found a way to do this with the 'HTTP AD' connector pointing towards the forms domain.  I inspected the network traffic while browsing the forms website in order to find the right endpoint (same as the 'Forms' connector!) and which fields to query for (/questions)

When authenticating I chose the base and service 'https://forms.office.com':

snip_form_flow_httpad.JPG

Make sure you choose Invoke HTTP request

snip_form_flow_questions.JPG

And to make it re-usable:

 

/formapi/api/forms('@{concat(triggerBody()?['resourceData']?['formId'])}')?$expand=questions

 

^Paste this into the field, not the expression popup.

In the response, questions is an array of objects, each object is a question from the form and it's related properties - most not useful.  For each object the property 'id' will match the key for it's response used in the builtin forms connector.  Another property of that same object 'title' contains the question text as seen in the form. 

That should get the questions and id relationship you're looking for.

I did not need to act on any of the questions, just wanted to pull them for viewing in an email so this may not be useful from here on depending on usecase:

snip_form_flow_parse_and_var.JPG

The full schema I used:

 

{
    "type": "object",
    "properties": {
        "questions": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "title": {
                        "type": "string"
                    },
                    "order": {
                        "type": "integer"
                    },
                    "type": {
                        "type": "string"
                    },
                    "required": {
                        "type": "boolean"
                    },
                    "questionInfo": {
                        "type": "string"
                    },
                    "groupId": {},
                    "status": {
                        "type": "string"
                    },
                    "subtitle": {},
                    "allowMultipleValues": {},
                    "trackingId": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

 

A loop to tie questions and responses together:

snip_form_flow_foreach_if.JPG

For the apply to each, select 'questions' from dynamic content.  This should work but it may become obsolete if the api calls change.  You might have to test run the flow to kick the dynamic content to show up.

 

The first fx body(...) - this should pull the Response based on the id from the current question.  The goal is to verify it's not empty.

 

@{body('Get_response_details')?[items('Apply_to_each')?['id']]}

 

^Paste this into the field, not the expression popup.

The output of the compose action pipes into the conditional left-hand side as dynamic content
The right hand side should be the expression: 

 

string('')

 

Leaving the 'if yes' branch empty (meaning 'skip if there is no response to the given question')

I append to my string variable:

 

"@concat('<b>', items('Apply_to_each')?['title'], '</b>  ', body('Get_response_details')?[items('Apply_to_each')?['id']], '<br><br>')"

 

^Paste this into the field, not the expression popup.

Again - it depends on the usecase, for me this creates a string to nicely fit into emails where the questions are in bold and the response is not. I have two 'breaks' in there for line spacing for readability. 

Hopefully this makes sense

@Demaul Thanks for putting together this amazing solution! The HTTP with Azure AD is a premium connector though. Any thoughts on being able to do this using a non-premium connector? We really just need a one time dump of the question id and question mapping so any other suggestions will be helpful too. I am working with a client and dont have access to their Azure environment otherwise logic apps would also have been an option for a one time mapping. Thoughts on what else I can use to at least get a one time mapping? Thanks again for the nice solution! 

This was very helpful, thanks for putting it out! Can you please elaborate on how to create JSON template that MS Flow can parse? I fail at this step. Thanks!

Adding to @Demaul 's post above and great work by the way, I played around with the Data Operation - Select, and came up with following solution: (going into details below)

FullFlowExpanded-Forms Questions and Answers.PNG

 


Here's the output from the Forms 'Get Response Details' with the question ids and corresponding answers.

FormAnswersOutput.PNG

Here's the results of the 'Invoke an HTTP request' which shows the array of questions with "id" matching the answer above, and the "title" which is the actual question literal

Invoke HTTP request Output.PNG

 

It may help to think of the "Select" action in a similar way to "Apply to Each" action or "For each" in other scripting languages, but "Select" performs changes across items in the array in one action.

From the the entire outputs above we only need to iterate through "questions" array, so we append  ?['questions'] to the outputs body like so:
Select Q and A.PNG

We can then address each item() directly so:

Question = item()?['title']

For the Answer, we need to look for the item()?['id'] within the body of the outputs from Get Response Details, so:

Answer = body('Get_response_details')?[item()?['id']]

 

The outputs of the Select action gives us a nice array of Question and Answer:

Select QandQ outputs.PNG

 

This array can be used to Create HTML table or Create CSV table. The output of these can simply be added to an email body or attached as a csv file.

Create HTML output.PNG

 

Hope this is helpful to someone

Anonymous
Not applicable

Hi @Demaul


I am trying to group the questions by sections, but I can't find the property for that. I found the property "groupId" but I noticed that just the MatrixChoice questions have a value, the others are Null.

 

Nayi94_0-1616103799050.png


Can you help me please? Thank you

cbathis
Regular Visitor

@Demaul Thanks for the solution. This is working fine till 22nd July. Suddenly I'm getting below error.

{
  "error": {
    "code""",
    "message""The query specified in the URI is not valid. The property 'questions' cannot be used in the $expand query option."
  }
}
 
Could you please assist on this?

I am also getting the same issue. Property 'questions' cannot be used in the $expand query option. Can someone help us with this? 

 

Thank you

 

Anonymous
Not applicable

Yeah me too face the same issue please help on us.

cbathis
Regular Visitor

Temp Fix : It works for me

 

/formapi/api/[Tenant ID]/users/[Form creator oid]/light/runtimeFormsWithResponses('@{concat(triggerBody()?['resourceData']?['formId'])}')?$expand=questions

Anonymous
Not applicable

@cbathis Hi, How to get Form creator Oid?

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages