0

I am trying to add dynamic data into AdaptiveCard by Groovy, then deploy it into Microsoft Teams.

It is working in Adaptive Card designer.

enter image description here

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Container",
            "$data": [{"name":"Aspentech ProMV","status":"Rejected"},{"name":"Testing","status":"Approved"}],
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "${name}",
                                    "wrap": true,
                                    "size": "Large",
                                    "fontType": "Default"
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "ActionSet",
                    "actionsOrientation": "horizontal",
                    "actions": [
                        {
                            "type": "Action.Submit",
                            "title": "Quick Approve"
                        }
                    ]
                }
            ]
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.4"
}

its calling ${name} from ${data}, but when I def it by Groovy below:

**requests: [{"name":"Aspentech ProMV","status":"Rejected"},{"name":"Testing","status":"Approved"}]**

then add it into Card, it can get the requests data successful, but seems it could not call ${name} from ${data} just in Teams.(its working in AdaptiveCard designer preview) enter image description here

how can I make it work in Teams?

Islam Elbanna
  • 1,438
  • 2
  • 9
  • 15
Ray Huang
  • 11
  • 1
  • The Adaptive Card Templating SDKs make it easy to populate a card template with real data on any supported platform. Please refer this [document](https://learn.microsoft.com/en-us/adaptive-cards/templating/sdk) which explains how to add dynamic data into Adaptive Card. Also refer [this thread](https://stackoverflow.com/questions/59542964/how-to-convert-custom-json-to-adaptive-card-json-format/59544467#59544467) which explains thoroughly on this topic. – Prasad-MSFT May 31 '23 at 10:34

1 Answers1

1

I found out the workaround.
def name map first:

name = ["name": "Aspentech ProMV", "name": "Testing"]

def data to include card item type, then call ${name} which we def before:

data = ["type": "TextBlock", "text": ${name}]

then use the ${date} in your card.

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "Software Name"
                        }
                    ]
                }
            ]
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": "${data}
                }
            ]
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.4"
}

We use this workaround because Microsoft Teams and Powerautomate could not support repeating items yet.

Reference: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Repeating-items-in-Teams-adaptive-cards/td-p/884421

Anonymous
  • 835
  • 1
  • 5
  • 21
Ray Huang
  • 11
  • 1