Forum Discussion
How do I change the color of text based on a boolean field in sharepoint
Justmeck I just tested using this JSON and it works fine with the modifications I suggested above:
{
"elmType": "div",
"attributes": {
"class": "ms-borderColor-neutralTertiary"
},
"style": {
"width": "99%",
"border-top-width": "0px",
"border-bottom-width": "1px",
"border-left-width": "0px",
"border-right-width": "0px",
"border-style": "solid",
"margin-bottom": "16px"
},
"children": [
{
"elmType": "div",
"style": {
"display": "flex",
"box-sizing": "border-box",
"align-items": "center"
},
"children": [
{
"elmType": "div",
"attributes": {
"iconName": "Group",
"class": "ms-fontSize-42 ms-fontWeight-regular ms-fontColor-themePrimary",
"title": "Details"
},
"style": {
"flex": "none",
"padding": "0px",
"padding-left": "0px",
"height": "36px"
}
}
]
},
{
"elmType": "div",
"attributes": {
"class": "ms-fontColor-neutralSecondary ms-fontWeight-bold ms-fontSize-24"
},
"style": {
"box-sizing": "border-box",
"width": "100%",
"text-align": "left",
"padding": "21px 12px",
"overflow": "hidden",
"color": "=if([$Fallig],'Red','')"
},
"children": [
{
"elmType": "div",
"txtContent": "='Kontaktinformationen für ' + [$Title]"
}
]
}
]
}
Output:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- JustmeckNov 29, 2023Copper ContributorThank you for the quick response but it dosnt work for me now the header shows but maby it has something to do with the colum because it is a calculated one or it has something to do with the fact that i have sharepoint in german? My calculated colum is =WENN(DATWERT(Erinnerung_fällig_am)<HEUTE();WAHR;FALSCH) so =IF(DATVALUE(Reminder)<TODAY();TRUE;FALSE) or something like that in english
- ganeshsanapNov 29, 2023MVP
Justmeck It works with calculated Yes/No (boolean) column as well:
Try using correct internal name of your column in the JSON. Alternatively, you can try expression like:
"color": "=if([$Fallig]==true,'red','')"
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- JustmeckDec 04, 2023Copper ContributorNothing works now its always green. I even changed the colume to a number so true is 1 and false is 0 and typed this "color": "=if([$Fallig]==1,'red','green')" but its just green all the time