SharePoint Asked by lieptas on January 2, 2022
I am trying to set custom formatting for date field and followed the guide here: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#apply-conditional-formatting.
I have written the code below, but it doesn’t respect multiple if conditions – none of the specified colors work unfortunately.
Perhaps someone could advice, what could be the issue?
{
"$schema":"https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType":"div",
"attributes":{
"class":"=if(@currentField >= @now + 604800000,'#FF6347', if(@currentField >= @now + 1209600000, '#FFD700', if(@currentfield >= @now + 1814400000, '#32CD32', '')))"
},
"children":[
{
"elmType":"span",
"style":{
"display":"inline-block",
"padding":"0 4px"
},
"attributes":{
"iconName":"=if(@currentField >= @now + 1814400000,'Error', '')"
}
},
{
"elmType":"span",
"txtContent":"@currentField"
}
]
}
conditions:
Woould like the "GOOD" to apply to >60 days and the items @ 60 days to display as a darker golden color - any suggestions based on this:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField <= @now + 864000000,'sp-field-severity--blocked', if(@currentField <= @now + 2592000000, 'sp-field-severity--warning', if(@currentfield <= @now + 5184000000, 'sp-field-severity--good', 'sp-field-severity--good')))"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": "=if(@currentField <= @now + 1814400000,'Error', '')"
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}
Answered by ShareDeveloper on January 2, 2022
I realised I had a logic mistake. The conditions I wanted to fulfil were:
The following code worked as expected (except, I wasn't able to use HEX color codes and instead used Conditional formatting option titles based on Excel):
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField <= @now + 604800000,'sp-field-severity--blocked', if(@currentField <= @now + 1209600000, 'sp-field-severity--warning', if(@currentfield <= @now + 1814400000, 'sp-field-severity--good', 'sp-field-severity--good')))"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": "=if(@currentField <= @now + 1814400000,'Error', '')"
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}
Answered by lieptas on January 2, 2022
I can see that you have mistakenly applied these conditions to class
instead of applying it to color
property of style
attribute.
Try below JSON code, it should work for you:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"color": "=if(@currentField >= @now + 604800000,'#FF6347', if(@currentField >= @now + 1209600000, '#FFD700', if(@currentfield >= @now + 1814400000, '#32CD32', '')))"
},
"children": [{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": "=if(@currentField >= @now + 1814400000,'Error', '')"
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}
Answered by Ganesh Sanap on January 2, 2022
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP