Forum Discussion
Json formatting - How to use the Moderation Status field
I have activated content approval on my list and I would like to format my form using the configure layout option to have a header that changes color based on the Approval Status Column.
But the no matter what I change my header keeps showing red. Is the $_ModerationStatus the right one to use?
See JSON below:
{
"elmType": "div",
"style": {
"display": "flex",
"justify-content": "space-between",
"border-radius": "10px",
"padding": "18px",
"font-size": "24px"
},
"attributes": {
"class": "=if([$_ModerationStatus] == 'Approved', 'ms-bgColor-greenLight', if([$_ModerationStatus] == 'Draft', 'ms-bgColor-blueLight', if([$_ModerationStatus] == 'Pending', 'ms-bgColor-warning', if([$_ModerationStatus] == 'Rejected', 'ms-bgColor-red', 'ms-bgColor-orangeLight')))) + ' ms-fontColor-neutralPrimary'"
},
"children": [
{
"elmType": "div",
"attributes": {
"iconName": "textDocument",
"class": "ms-fontSize-42 ms-fontWeight-regular ms-fontColor-themePrimary",
"title": "Details"
},
"style": {
"flex": "none",
"padding": "0px",
"padding-left": "0px",
"height": "36px"
}
},
{
"elmType": "div",
"txtContent": "[$Title]"
},
{
"elmType": "div",
"attributes": {
"iconName": "=if([$_ModerationStatus] == 'Approved', 'CompletedSolid', if([$_ModerationStatus] == 'Draft', 'PinnedSolid', if([$_ModerationStatus] == 'Pending', 'TestBeakerSolid', if([$_ModerationStatus] == 'Rejected', 'WarningSolid', 'Blocked2Solid'))))",
"title": "[$Status]"
}
}
]
}
Patrick Rote Microsoft added official support for Approval Status column in JSON formatting sometime back.
Due to this update, the @currentField and [$_ModerationStatus] will resolve to internal code (enum value) and @currentField.displayValue and [$_ModerationStatus.displayValue] will resolve to the localized string.
So, try using [$_ModerationStatus.displayValue] instead of [$_ModerationStatus] in your JSON or use enum values to compare instead of text value.
- 0 : Approved
- 1 : Denied
- 2 : Pending
- 3 : Draft
- 4 : Scheduled
Similar thread: Column Formatting with Approval Status
Update:
As per the current design of SharePoint JSON formatting, you can refer only those columns which are shown on list forms in your JSON.
Seems like Approval Status column is not visible in list forms hence you are unable to use its value in JSON formatting.
Similar thread: Can ID column be displayed when configuring a list form header using JSON?
Example:
For simple SharePoint list with only Title and Approval Status column, I can only see the Title column on list form and only below column values are available in page context while applying JSON in header layout:
Related Read: How to find the Internal name of columns in SharePoint Online?
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.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs