Jan 06 2023 09:55 AM
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 format change:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"background-color": "=if([$STATVal] == 'Committed', '#FFA07A, '')"
}
}
Jan 07 2023 02:36 AM - edited Jan 07 2023 05:47 AM
@Czyz0 add the txtContent": "@currentField" line as shown below and make sure that your #FFA07A has a closing single quote which it doesn't at the moment. The correct JSON is:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if([$STATVal] == 'Committed','#FFA07A', '' )"
}
}
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
Jan 08 2023 04:05 AM
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
Jan 09 2023 08:16 AM
Jan 09 2023 08:18 AM
Jan 09 2023 08:18 AM
Jan 09 2023 09:01 AM
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