Forum Discussion
Czyz0
Jan 06, 2023Copper Contributor
Change field BACKGROUND color based on value of ANOTHER field drop down
I'm using the JSON formatting field on column ESTVal, which is a number field. I want to show a background of GREEN when the selection in STATVal is Committed. I'm trying this JSON and see no forma...
SvenSieverding
Jan 08, 2023Bronze Contributor
Hi Czyz0,
In addition to what RobElliott said:
You also need to make sure, that your "STATVal" field is in the view. You cannot access fields that are not being displayed.
Best Regards,
Sven
- Czyz0Jan 09, 2023Copper ContributorI'm applying the JSON to the ESTVal column in the list. For my testing purposes, I do have both the ESTVal and ESTStat in the view, but the end goal is to hide the Stat from the view, as the bg color will become a visual representation of the status. So, even if I get it working, it sounds like I'll break it when I simplify the view.... 😕
Back to an excel via attached data set....- SvenSieverdingJan 09, 2023Bronze Contributor
Well, alternatively you could get creative:
Create a calculated column and concatenate ESTStat, a seperator sign (like "-") and ESTVal
=[ESTStat]&"-"&[ESTVal]This concatenates the status and the value into a single field.
Then use this json formatting on that field to extract the value into txtContent (Everything after "-") and apply the styling if everything in front of "-" equals "Commited"{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "=substring(@currentField.displayValue,indexOf(@currentField.displayValue,'-')+1,indexOf(@currentField.displayValue + '^', '^'))", "style": { "background-color": "=if(substring(@currentField.displayValue,0,indexOf(@currentField.displayValue,'-')) == 'Committed','#FFA07A', '' )" } }
Then you can hide both fields ESTStat and ESTVal and leave the new field in the view.
Best Regards,
Sven