0

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]"
            }
        }
    ]
}
5
  • Try using [$_ModerationStatus.displayValue] instead of [$_ModerationStatus]. Mar 7, 2023 at 3:57
  • Hi @naijacoder, does below answer help you in any way? Mar 8, 2023 at 14:28
  • Thanks Ganesh.Will update soon
    – naijacoder
    Mar 9, 2023 at 20:03
  • Sure, let me know if you need any further information Mar 10, 2023 at 2:47
  • Hi @naijacoder, does below answer help you in any way? If yes, Please Upvote(^) and accept as an Answer as it helped you & it will help others with similar question in future to find the correct answer easily. Oct 17, 2023 at 8:08

1 Answer 1

0

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:

enter image description here

Related Read: How to find the Internal name of columns in SharePoint Online?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.