power-automateadaptive-cards

PowerAutomate Adaptive Cards - Input.Choice set from dynamic list/array


I am in the early stages of learning adaptive cards. I have an array filled with names/email addresses that is read from a sharepoint member list. I am attempting to display this list as an assignment field in an adaptive card.

I have been able to make the card work with hardcoded values for the title/value.

"actions": [
    {
        "type": "Action.ShowCard",
        "title": "Assign Request",
        "card": {
            "type": "AdaptiveCard",
            "body": [
                {
                    "type": "Input.ChoiceSet",
                    "id": "AssignedMember",
                    "choices": [
                        {
                            "title": "Paul Smith",
                            "value": "Paul@mail.com"
                        },
                        {
                            "title": "Mike Jones",
                            "value": "Mike@mail.com"
                        }
                    ],
                    "errorMessage": "This is a required input",
                    "placeholder": "Please Choose",
                    "isRequired": true
                }
            ],
            "actions": [
                {
                    "type": "Action.Submit",
                    "title": "OK"
                }
            ],
            "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
        }
    },

Array Values: 

[
  {
    "@odata.type": "#microsoft.graph.user",
    "id": "a9b4ab8dfd78",
    "displayName": "Paul Smith",
    "mail": "Paul@mail.com",
  },
  {
    "@odata.type": "#microsoft.graph.user",
    "id": "b94bbcb08f",
    "displayName": "Mike Jones",
    "mail": "Mike@mail.com",
  {
    "@odata.type": "#microsoft.graph.user",
    "id": "96d9c39e6b",
    "displayName": "Todd Neal",
    "mail": "Todd@mail.com",

  }
]



Solution

  • Use a Select action from the Data operations connector.

    Sample Flow

    Sample Flow

    From = This is just the sample list of users you provided.

    With the next two fields, I just used what I felt worked, you can pick email or whatever.

    title = item()['id']

    value = item()['displayName']

    Result

    [
      {
        "title": "a9b4ab8dfd78",
        "value": "Paul Smith"
      },
      {
        "title": "b94bbcb08f",
        "value": "Mike Jones"
      },
      {
        "title": "96d9c39e6b",
        "value": "Todd Neal"
      }
    ]
    

    Result

    Then just inject the output of the Select into the choices array property in the adaptive card JSON.