Site icon JD Bots

Using When Condition in Adaptive Card

focused young ethnic woman with credit card and laptop

Photo by Liza Summer on Pexels.com

Drop an entire Adaptive Card JSON element when condition is met using the $when property. If $when condition is true, then only JSON element will be shown to the user else it will not be shown to the user.

Below is an example to work with $when property in Adaptive Card.

{
    "type": "AdaptiveCard",
    "$data": {
        "age": "19"
    },
    "body": [
        {
            "type": "TextBlock",
            "$when": "${age >= 18}",
            "text": "You are eligible!",
            "color": "good",
        },
         {
            "type": "TextBlock",
            "$when": "${age< 18}",
            "text": "You are not eligible!",
            "color": "warning"
        }
    ]
}

Thank you All!!! Hope you find this useful.


Exit mobile version