Search code examples
jsonbotframeworkadaptive-cards

Multiple if-else within json adaptive card


0

I'm new to adaptive cards and the usage of JSON conditional statements on adaptive cards.

Can I know if it is possible to change the color of an adaptive card text using multiple if-else statements? Such as having 3 color output options.

Also, does if-else statements support in adaptive cards version 1.0?

Below is a sample of code I found from here by asking a question before, however, does the version of the adaptive card affect the output by giving an if condition in the color?

{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"body": [
    {            
          "$data": "${AttendanceMonthly}",
          "type": "TextBlock",
          "weight": "bolder",
          "separator": true,
           "color": "${if(WorkedHours < 6, 'attention', 'good')}",
          "text": "Hours worked: ${WorkedHours}"
    }]

Solution

  • You can nest the if/else statements, like:

    ${if(WorkedHours < 6, 'attention', if(<condition>, <true>, <false>))}"
    

    However, you may benefit more from using some other logical operators, depending on what you're trying to accomplish.

    I don't recall which version began support of Adaptive Expression Language, but you may as well set to version 1.3, if you can. Note, however, that if you're using cards you created before May 2020, there might be some breaking changes in data binding.