cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Prodigy
Post Prodigy

Changing the colour of a list item depending on a field

Afternoon

 

I've set up a Flow which sends an email alert depending on a date. When the condition is hit I want the list item to change colour.

 

How I thought it would work is that I'd have a drop down field called Status which has 'Green', 'Amber' and 'Red'.

 

I'd have an update item action which would set the field depending on the date. I've got a calculated field with this formula:

="<div style='text-align:left; background-color:"&IF(Status="Green","green",IF(Status="Amber","amber",IF(Status="Red","red")))&"'>"&Status&"</div>"

 

If I change the Status to Green it changes the StatusColour to the formula saying 'Green' but doesn't change the colour. I've tried changing the word Red to #ff0000 and rgb(255, 0, 0) and it doesn't work. Any ideas?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: Changing the colour of a list item depending on a field

Hi @darrenfloyd666 if you are using a modern SharePoint list then your status column can be formatted directly (click the column header -> Settings -> Format this column) and doesn't need to be set via Power Automate. On most of my lists I have a background color set depending on the answer in the column:

columnFormat.png

The JSON code for your Green, Amber, Red would be:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"padding-left": "14px"
},
"attributes": {
"class": "=if(@currentField == 'Green', 'ms-bgColor-tealLight', if(@currentField == 'Red', 'ms-bgColor-red','ms-bgColor-orangeLighter')) + ' ms-fontColor-black'"
}
}

Come back with any questions about this.

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

View solution in original post

6 REPLIES 6
Highlighted
Super User III
Super User III

Re: Changing the colour of a list item depending on a field

Hi @darrenfloyd666 if you are using a modern SharePoint list then your status column can be formatted directly (click the column header -> Settings -> Format this column) and doesn't need to be set via Power Automate. On most of my lists I have a background color set depending on the answer in the column:

columnFormat.png

The JSON code for your Green, Amber, Red would be:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"padding-left": "14px"
},
"attributes": {
"class": "=if(@currentField == 'Green', 'ms-bgColor-tealLight', if(@currentField == 'Red', 'ms-bgColor-red','ms-bgColor-orangeLighter')) + ' ms-fontColor-black'"
}
}

Come back with any questions about this.

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

View solution in original post

Highlighted
Post Prodigy
Post Prodigy

Re: Changing the colour of a list item depending on a field

That's brilliant @RobElliott . Just a few questions. The Red option turns the field amber as opposed to red? Is there a way to turn the entire item Red, Green or Amber, and basically I need the colour to change when a an alert email is sent out by Flow so I guess I'm going to have to use a Flow action for that to update a field? 

Highlighted
Super User III
Super User III

Re: Changing the colour of a list item depending on a field

@darrenfloyd666  Sorry, I typed it too quickly and got the case of the first letter of Red wrong. I've corrected my post.

Yes you use the flow to update the column value but the formatting of that column is done with JSON and the colour will change depending on what the update has done to the column. By entire item every column in the item? I don't think that can be formatted this way but will check.

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

Highlighted
Post Prodigy
Post Prodigy

Re: Changing the colour of a list item depending on a field

Quick question @RobElliott 

 

When the drop down field 'Status' field is 'Out of Date' I want it to turn red, so changing the line to:

if(@currentField == 'Out of Date', 'ms-bgColor-red','ms-bgColor-orangeLighter'))

 

would do the trick but doesn't it just stays white? 

 

Super User III
Super User III

Re: Changing the colour of a list item depending on a field

Hi @darrenfloyd666 you could get this result:
red-green.png

by adding the following JSON syntax when you format the column:

{
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": {
      "operator": "?",
      "operands": [
        {
          "operator": "==",
          "operands": [
            "@currentField",
            "In Date"
          ]
        },
        "#40D66F",
        {
                      "operator": "?",
                      "operands": [
                        {
                          "operator": "==",
                          "operands": [
                            "@currentField",
                            "Out of Date"
                          ]
                        },
                        "#EF4213",
                        {
                          "operator": "?",
                          "operands": [
                            {
                              "operator": "==",
                              "operands": [
                                "@currentField",
                                "Extra field"
                              ]
                            },
                            "#EF4213",
                            ""
                          ]
                        }
                      ]
                 }
              ]
          }
    }
}

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

Highlighted
Post Prodigy
Post Prodigy

Re: Changing the colour of a list item depending on a field

Thanks @RobElliott  I just want the field (or list item but I know you said that might be tricky) to turn change colour when the drop down is selected. So 'Out of Date' = Red, but haven't used a lot of JSON before so don't know what to amend. Any help appreciated! 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Users online (6,300)