Share via

Sharepoint list header Json formatting

Ceres215678 20 Reputation points
Aug 31, 2023, 9:50 AM

I created a SharePoint list for user to place purchase order. When create a new item, the header will show "Submit a new order".

User's image

When viewing a item, the header will show "Order Status".

User's image

I would like to add a red text to remind user when create new item, When order type equals to Chemical - Non-DGMT, a text will appear under "submit a new order" that tell users to beware of sth like the following.

Screenshot 2023-08-31 174202

The code I use:

Please help. Thanks so much.

{
    "debugmode": "true",
    "elmType": "div",
    "attributes": {
        "class": "=if([$Status] == 'Completed', 'transparent', if([$Status] == 'Duplicate', 'transparent', if([$Status] == 'Blocked', 'transparent', if([$Status] == 'New', 'transparent','transparent'))))"
    },
    "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": "EntitlementPolicy",
                        "class": "ms-fontSize-42 ms-fontWeight-regular  ms-fontColor-black",
                        "title": "Issue"
                    },
                    "style": {
                        "flex": "none",
                        "padding": "0px",
                        "padding-left": "0px",
                        "height": "36px"
                    }
                }
            ]
        },
        {
            "elmType": "div",
            "attributes": {
                "class": "ms-fontColor-black ms-fontWeight-bold ms-fontSize-24"
            },
            "style": {
                "box-sizing": "border-box",
                "width": "100%",
                "text-align": "left",
                "padding": "21px 12px",
                "overflow": "hidden"
            },
            "children": [
                {
                    "elmType": "div",
                    "txtContent": "=if ([$Status] == '', 'Submit a new order', 'Order Status: ' + [$Status])"
                }
            ]
        }
    ]
}

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,550 questions
0 comments No comments
{count} votes

Accepted answer
  1. ChengFeng - MSFT 5,045 Reputation points Microsoft External Staff
    Sep 1, 2023, 7:25 AM

    Hi @Ceres215678

    I made a test for your reference:User's image

    Here is code:

    {
        "elmType": "div",
        "attributes": {
            "class": "ms-borderColor-neutralTertiary"
        },
        "style": {
            "display": "flex",
            "flex-direction": "column",
            "align-items": "flex-start",
            "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"
                        },
                        "children": [
                            {
                                "elmType": "div",
                                "txtContent": "='Contact details for ' + [$Title]"
                            }
                        ]
                    }
                ]
            },
            {
                "elmType": "div",
                "style": {
                    "color": "red"
                },
                "txtContent": "=if([$Test] == 'Choice 1', '1', 'Other Value')"
            }
        ]
    }
    
    
    

    I modified it according to the code you provided, please try:

    {
        "debugmode": "true",
        "elmType": "div",
        "attributes": {
            "class": "=if([$Status] == 'Completed', 'transparent', if([$Status] == 'Duplicate', 'transparent', if([$Status] == 'Blocked', 'transparent', if([$Status] == 'New', 'transparent','transparent'))))"
        },
        "style": {
             "display": "flex",
            "flex-direction": "column",
            "align-items": "flex-start",
            "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": "EntitlementPolicy",
                            "class": "ms-fontSize-42 ms-fontWeight-regular  ms-fontColor-black",
                            "title": "Issue"
                        },
                        "style": {
                            "flex": "none",
                            "padding": "0px",
                            "padding-left": "0px",
                            "height": "36px"
                        }
                    }
                ]
            },
            {
                "elmType": "div",
                "attributes": {
                    "class": "ms-fontColor-black ms-fontWeight-bold ms-fontSize-24"
                },
                "style": {
                    "box-sizing": "border-box",
                    "width": "100%",
                    "text-align": "left",
                    "padding": "21px 12px",
                    "overflow": "hidden"
                },
                "children": [
                    {
                        "elmType": "div",
                        "txtContent": "=if ([$Status] == '', 'Submit a new order', 'Order Status: ' + [$Status])"
                    }
                ]
            },
            {
                "elmType": "div",
                "style": {
                    "color": "red"
                },
                "txtContent": "=if([$Order Type] == 'Chemical - Non-DGMT', '*Remain ', 'Other Value')"
            }
        ]
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Ceres215678 20 Reputation points
    Sep 4, 2023, 9:52 AM

    I struggled in it for a long time. Thanks so much for you help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.