Mar 26 2024 10:09 AM
I'm attempting to do conditional column formatting with JSON to assign a color to those fields showing any value, and no color for those that are a Null value. I found this online, which according to the discussion should work, I'm so new to this function, I don't even know where this string should be placed in the JSON code of the body.
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "debugMode": true, "elmType": "div", "attributes": { "class": "=if(@currentField,'sp-field-severity--good','')" }, "children": [ { "elmType": "span", "style": { "display": "inline-block", "padding": "0 4px", "color": "=if([@currentField] == '', 'red', 'black')" } }, { "elmType": "span", "txtContent": "@currentField" } ] }
This is a portion of my current JSON body, where should the above schema string go here if I want the field "Title" to be a different color if there is a Value in the field? And no color if the field is Null value?
{
"sections": [
{
"displayname": "Administration & Communication",
"fields": [
"Status",
"Priority",
"Quantity",
"Segment",
"Responder Email",
"Assigned to",
"Request Type",
"KiteWorks Access",
"Notes to Requestor",
"Deeplink"
]
},
{
"displayname": "General Course Info",
"fields": [
"Title",
"Instructions",
"File Type",
"Content File Name",
"Training Hours",
"Mobile Enabled",
"Keywords",
"Training Description",
"Languages",
"Translation File",
"Course Evaluation",
"Learning Type",
"Business Unit",
"Completion Criteria",
"Reporting Tag",
"Subjects/Competencies"
]
}
Thank you for any help!
Mar 26 2024 10:45 PM
Solution
Are you trying to change the color in list view using column formatting or on list form using form formatting?
First schema code given is for column formatting and seconds schema code is for form "body" formatting.
Unfortunately, form "body" formatting does not support conditional schema like column/view/form header/form footer formatting:
Unlike the header and the footer, body configuration only allows defining one or more sections and adding one or more columns into each of those sections.
Source: Configure custom body with one or more sections
Related read: Make section border/separator invisible in list form body custom layout with JSON
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.
Mar 27 2024 06:03 AM
Mar 26 2024 10:45 PM
Solution
Are you trying to change the color in list view using column formatting or on list form using form formatting?
First schema code given is for column formatting and seconds schema code is for form "body" formatting.
Unfortunately, form "body" formatting does not support conditional schema like column/view/form header/form footer formatting:
Unlike the header and the footer, body configuration only allows defining one or more sections and adding one or more columns into each of those sections.
Source: Configure custom body with one or more sections
Related read: Make section border/separator invisible in list form body custom layout with JSON
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.