Search code examples
adaptive-cards

Binding data to Adaptive Card Choice Set Templates using Templating


I'm trying to bind some data to an Adaptive Card Choice Set using templating. I've been experimenting in the designer with an element like this:

{
        "type": "Input.ChoiceSet",
        "placeholder": "Select Assign",
        "id": "Assign",
        "label": "Assign",
        "choices": [
            {
                "title": "${title}",
                "value": "${value}"
            }
        ],
        "$data": "${Detail}"
    }

and data like this:

"Detail": [
    {
              "title": "Mike",
              "value": "[email protected]"
          },
          {
              "title": "Zoe",
              "value": "[email protected]"
          },
          {
              "title": "Jim",
              "value": "[email protected]"
          }

]

but then I get three dropdowns in the preview: preview

So I'm close but not there yet, is it possible to get this as one dropdown?


Solution

  • The data assignment is just at the wrong place. You need to put data on the exact element you want to apply the array to.

    Try this card here with your Data

    {
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "Input.ChoiceSet",
            "placeholder": "Select Assign",
            "id": "Assign",
            "label": "Assign",
            "choices": [
                {
                    "$data": "${$root['Detail']}",
                    "title": "${title}",
                    "value": "${value}"
                }
            ]
        }
    ]
    }