Skip to main content

Notifications

Community site session details

Community site session details

Session Id : kJ65jRQej3Kq52AQzZz0YC
Power Automate - Building Flows
Answered

Adding background color to HTML table cell based on condition

Like (0) ShareShare
ReportReport
Posted on 4 Sep 2023 14:27:19 by 52

I created a table in an email using HTML code (because it worked better than creating the table with Create HTML Table).  Here is the part of the HTML:

 

 SMiller3_0-1693836379967.png

 

that produces this result below the column headers:

 

Entry

Previous

UPDATE

Quantity

1

2

 

I need to change the background color of the Quantity UPDATE cell when the quantity changes from previous.

 

When I create the following formula in a compose and place its output right before output for the update column, it just puts the word yellow before the 2.  

 

if(outputs('Get_changes_for_an_item_or_a_file_(properties_only)')?['body/ColumnHasChanged/Quantity'],'yellow',)
 
How should the expression look to achieve desired result and where exactly should the output be placed in the HTML?
 
TYIA
  • Verified answer
    SMiller3 Profile Picture
    52 on 14 Sep 2023 at 17:49:43
    Re: Adding background color to HTML table cell based on condition

    For anyone that's interested, I was able to figure this out.

     

    Based on the original example, I created a compose action with if expression:

     

    SMiller3_0-1694713120619.png

     

    In the body of the email, I inserted the outputs from above right before <p class=MsoNormal following the <td for the relevant cell:

     

    SMiller3_1-1694713234700.png

     

    Notice (highlighted in yellow) that the space between <p and class needs to be removed and another </p> needs to be added (its initial<p is in the compose action).

     

    The result is:

    SMiller3_2-1694713547061.png

     

  • SMiller3 Profile Picture
    52 on 13 Sep 2023 at 16:26:34
    Re: Adding background color to HTML table cell based on condition

    I think I have the formula with the condition, but am having trouble placing it in the html.

     

    I made a simpler expression just to get the cell to turn yellow:

     

    style=\"background-color:yellow;

     

    and put it in the html as below:

     

    SMiller3_0-1694621834120.png

    This is the result:

    SMiller3_1-1694621891119.png

    If placed right before dynamic content, I get this:

    SMiller3_2-1694621956223.png

    And when I placed the style color expression between <td and width=252, I get this:

     

    SMiller3_3-1694622175888.png

     

    Does anyone know where to put the expression so it will look like this?

    SMiller3_4-1694622304743.png

     

     

  • ChristianAbata Profile Picture
    8,947 Most Valuable Professional on 05 Sep 2023 at 00:11:14
    Re: Adding background color to HTML table cell based on condition

    hi @SMiller3  here is an example about using if as expression

    If (true/false,if true,if false)

    As you can see you need to provide first a true or false value. How can you get that? maybe using another expression like empty(). For example: If Column is empty then true, if no then false.

     

    If(empty(Column),'ShowBlackColor', ShowYellow)

     

    As you are working on HTML I'll replace the css code with my expression.

     

    so you can try if(true/false,'style='color:black'',style='color:yellow')

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard
Loading started