question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Authoring] $if conditional does not work on text color

See original GitHub issue

Problem Description

I am unable to switch the text color with an $if conditional. The error I get is

[Parse] Invalid value “${if(priceChange >= 0, ‘good’, ‘attention’)}” for property “color”.

Card JSON

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.5",
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "THIS IS A TEST ${priceChange}",
                    "wrap": true,
                    "color": "${if(priceChange >= 0, 'good', 'attention')}"
                }
            ]
        }
    ]
}




Data.json
{
    "priceChange": 4
}

Screenshot

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
anna-dinglercommented, Oct 26, 2022

Hey @g138,

The templating expressions are evaluated using our adaptivecards-templating package (https://www.npmjs.com/package/adaptivecards-templating). Templates are expanded using the templating package, and then the resulting card is parsed by the Adaptive Cards library.

Since the template you provided works in the designer, there is a chance that PowerAutomate doesn’t use the templating library. I would reach out to them here to see if they have any information on this.

1reaction
g138commented, Oct 27, 2022

Thanks, @anna-dingler for the response, using the library solved my issue on the node side, separate from this preview mode helped to see the change on the adaptivecard.io

var ACData = require('adaptivecards-templating');

let cardJson = {
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
          {
                "type": "TextBlock",
                "size": "Medium",
                "weight": "Bolder",
                "text": "${number}",
                "color": "${if(number > 0, 'good', 'attention')}"
          }
    ]
}

let finalCardJson = cardJson.expand({
        $root: {
            number: 10
        },
})

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

$if conditional does not work on text color - Adaptive cards
Hi, Anyone know how to solve the problem of if conditional statement in adaptive card with power automate? Having this issue, thanks.
Read more >
IF Statement for Text Color
I want to have the value in C1 equal to B1 if the text in A1 is red. Is there a way to...
Read more >
JavaScript if statement changing text color - html
I was not calling the function with the if statement. so what I did was called the function from the table replacing +...
Read more >
Conditional Formatting Fill Color But Don't Change Font ...
Hi, I've got a combo box with 4 options that change the font color of a range of cells (to red, blue ,...
Read more >
Excel - Change Text Color Within “IF” Formula
Apply conditional formatting on the cell where the text needs to change color (the one with your above formula). Create a new rule:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found