Adaptive card json for microsoft form choice reponse

318 Views Asked by At

I am using power automate to post a card to Microsoft Teams whenever a Microsoft Forms response is submitted. The Microsoft form includes a choice field ("Operating System") that has 3 options ("iOS", "Android", and "Both"). I am using Adaptive Card json to make the card look better when it is posted to MS Teams. Inside the Adaptive Card json I am using Dynamic content to include the responses from the MS Form that was submitted.

I am getting a failure whenever I try to include the choice field response (Operating System): (I think this is because the choice responses for operating system are not a text type buy possibly array?)

enter image description here

Could anyone provide a solution to handle the Operating System choice response?

Here is the error I am getting:

Line 39 is the line "text": "Operating System",(the dynamic content one) and if I select Android as the response this is the error that appears. If I select iOS as the response, the error will say "I" instead of "A".

Microsoft.Azure.ProcessSimple.Data.Entities.Exceptions.ProcessSimpleDataException: The specified Teams flowbot adaptive card request is missing or invalid. The tracking Id is '{0}'. ---> Newtonsoft.Json.JsonReaderException: After parsing a value an unexpected character was encountered: A. Path 'body[5].text', line 39, position 17.

EDIT: Adding all JSON for adaptive card:

{
  "type": "AdaptiveCard",
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.2",
  "body": [
    {
      "type": "TextBlock",
      "text": "Title",
      "size": "large",
      "weight": "bolder",
      "wrap": true
    },
    {
      "type": "TextBlock",
      "text": "@{outputs('Get_response_details')?['body/id#']}",
      "wrap": true
    },
    {
      "type": "TextBlock",
      "text": "Description",
      "size": "large",
      "weight": "bolder",
      "wrap": true
    },
    {
      "type": "TextBlock",
      "text": "@{outputs('Get_response_details')?['body/id#']}",
      "wrap": true
    },
    {
      "type": "TextBlock",
      "text": "Operating System",
      "size": "large",
      "weight": "bolder",
      "wrap": true
    },
    {
      "type": "TextBlock",
      "text": "@{outputs('Get_response_details')?['body/id#']}",
      "wrap": true
    }
  ]
}

EDIT: Adding MS Forms response json

{
"responder":"[email protected]",
"submitDate":"8/23/2023 2:55:52 PM",
"id1":"This is a title",
"id2":"This is a description",
"id3":"[\"iOS\"]",
"id4":"",
"id5":""
}
2

There are 2 best solutions below

3
Sayali-MSFT On

You need to construct the correct format for Input.ChoiceSet,Like below-

  {
        "type": "Input.ChoiceSet",
        "isMultiSelect":true,
        "placeholder": "",
        "id": "groceries",
        "isRequired": true,
        "label": "Groceries",
        "spacing": "Medium",
        "choices": 
        @{variables('choicevariable')}
    }

enter image description here Also refer the below thread- https://powerusers.microsoft.com/t5/Building-Flows/Turn-CSV-into-Adaptive-Card-Choices/m-p/1623743#M180829

0
Skin On

Yes, the data coming out is an array but even more interesting is that it's a serialised string. For that reason, your error is a bit bizarre. If it's just a string, it should map through.

Either way, if you want to parse the values, you can do it a couple of ways.

Firstly, I placed your forms response JSON in a variable so I could use it to demonstrate my answer. The name of my variable is Forms Response.

{
    "responder": "[email protected]",
    "submitDate": "8/23/2023 2:55:52 PM",
    "id1": "This is a title",
    "id2": "This is a description",
    "id3": "[\"iOS\"]",
    "id4": "",
    "id5": ""
}

Note: Because the value is a string, you need to convert it to an array first and to do that, you need to use the json expression. You'll see that used in my answers.

First Option

You can use the first expression if you always expect a single value in the answer.

first(json(variables('Forms Response')?['id3']))

First Option

Join Option

Alternatively, if you expect more than one answer, you can always use the join expression to string them all together.

To demonstrate this one. I changed ID3 to look like this ...

 "id3": "[\"iOS\", \"Android\"]"

This is the expression I used ...

join(json(variables('Forms Response')?['id3']), ', ')

... and this is the outcome.

Using Join