Forum Discussion
eenochs-turner
May 05, 2020Brass Contributor
JSON Statement Help
I have a JSON statement that I'm getting an error on. Error is
JSON Statement
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"debugMode": true,
"txtContent": "@currentField",
"style": {
"color": "if=([$EMR_x0020_Effective_x0020_Date] == ' ' && [$EMR_x0020_Effective_x0020_Date] +31556952000 <= @now, '#ff0000', '#000000')"
}
}
I'm trying to look at one column and if the EMR Effective Date is less than the date + a year or if the entry is blank the text will be red. Error has to be in the statement but not sure where it is at.
- Vikram_SamalSteel Contributor
eenochs-turner In the below code i could see two things which might need to be corrected
"color": "if=([$EMR_x0020_Effective_x0020_Date] == ' ' && [$EMR_x0020_Effective_x0020_Date] +31556952000 <= @now, '#ff0000', '#000000')"
- Your are using && operator instead of ||
- You are trying to set color for a text which is blank which will never happen
If you want to achieve something like this I will write something like this:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "attributes": { "class": "=if(toString([$Date]) =='','sp-field-severity--severeWarning',if([$Date] <= @now-31556952000,'sp-field-severity--severeWarning', ''))" }, "children": [ { "elmType": "span", "style": { "display": "inline-block", "padding": "0 4px" } }, { "elmType": "span", "txtContent": "@currentField" } ] }
Hope this helps!