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
1 Asked on December 3, 2020 by madhan
sharepoint addin sharepoint designer sharepoint enterprise sharepoint foundation
2 Asked on December 3, 2020 by dilip-kumar-yadav
2 Asked on December 3, 2020 by tarun
office 365 developer pnp powershell powershell sharepoint online
1 Asked on December 2, 2020 by datalearner
sharepoint administration sharepoint enterprise sharepoint online sharepoint server
1 Asked on December 1, 2020 by thomas-de-wulf
microsoft graph sharepoint online sharepoint rest api subscriptions
4 Asked on November 30, 2020 by chandhu-vutukuru
2013 sharepoint enterprise sharepoint foundation sharepoint online sharepoint server
1 Asked on November 30, 2020 by user1816979
0 Asked on November 30, 2020
1 Asked on November 30, 2020 by akshay-manke
0 Asked on November 30, 2020 by lancelot
1 Asked on November 29, 2020 by burre-ifort
2 Asked on November 29, 2020 by sukhdev-zala
1 Asked on November 29, 2020 by naveen
sharepoint enterprise sharepoint foundation sharepoint server
1 Asked on November 28, 2020 by saaru-lindestkke
2 Asked on November 26, 2020 by kaddrik
2 Asked on November 26, 2020 by thecoder
2 Asked on November 17, 2020 by lies-ugent
1 Asked on November 16, 2020
1 Asked on November 8, 2020 by user92615
1 Asked on November 4, 2020 by omega
best practices sharepoint online spfx spfx extensions spfx webparts
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP