Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to change the color of an adaptive card output which comes from the database according to its value eg: if workhour < 6 = color of the adaptive card showing the work hours must be red. if it is greater than 6 hours the work hours must be displayed in green.

Any idea of how I must achieve this?

Below is a part of the JSON code along with data I call from the database. Also, I will be implementing this on Microsoft Teams.

"type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "weight": "bolder",
              "text": "Work Hours"
            },
            {
              "$data": "${AttendanceMonthly}",
              "type": "TextBlock",
              "weight": "bolder",
              "separator": true,
              "text": "${WorkedHours}"
            }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use if to set the color to attention or good. See this example:

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

Based on your Data this would make the text red for workedHours below 6. Have in mind that you can only set a color to "Attention", "Good" etc and not a color code directly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...