SOLVED

SP List Header - New Item shows user display name at Adding or Editing item

Copper Contributor

Hi There,
I have a SP list that has a user directory pickup filed "requestor". I have updated the header which should Show "Request of: Leonard Jackson" at the Header when Add or Edit any data in that list. My code is following which is not working:

 

{
    "debugmode": "true",
    "elmType": "div",
    "attributes": {
        "class": "ms-bgColor-green"
    },
    "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": "MobileSelected",
                        "class": "ms-fontSize-42 ms-fontWeight-regular  ms-fontColor-white",
                        "title": "Software Name"
                    },
                    "style": {
                        "flex": "none",
                        "padding": "0px",
                        "padding-left": "0px",
                        "height": "36px"
                    }
                }
            ]
        },
        {
            "elmType": "div",
            "attributes": {
                "class": "ms-fontColor-white 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 ([$Title] == '', 'New Item', 'Request of: ' + [$Requestor.DisplayName])"
                }
            ]
        }
    ]
}

 

Its not showing the username as following. But If the List filed "Requestor" is not a Directory pick, it works. 

Capture.JPG

 

6 Replies
best response confirmed by leonardbd (Copper Contributor)
Solution

@leonardbd Use .title instead of .DisplayName. I just tested and it is working fine for me. Also, make sure you are using correct internal name of your people picker column in JSON. You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?  

 

{
    "elmType": "div",
    "attributes": {
        "class": "ms-bgColor-green"
    },
    "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": "MobileSelected",
                        "class": "ms-fontSize-42 ms-fontWeight-regular  ms-fontColor-white",
                        "title": "Software Name"
                    },
                    "style": {
                        "flex": "none",
                        "padding": "0px",
                        "padding-left": "0px",
                        "height": "36px"
                    }
                }
            ]
        },
        {
            "elmType": "div",
            "attributes": {
                "class": "ms-fontColor-white 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 ([$Title] == '', 'New Item', 'Request of: ' + [$Requestor.title])"
                }
            ]
        }
    ]
}

 


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.

@leonardbd Here is the output while using JSON in my above response: 

ganeshsanap_0-1693827384700.png


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.

@ganeshsanap 

Thanks for the reply. It works just fine. But I have another list that has "Software Name" as a choice field instead of a Directory name pick. That isn't working. I guess for the SPACE in the filed name. Dont know how to write that in code. 

here is it .. the last part of the Header code \

......
........               

 {
                    "elmType": "div",
                    "txtContent": "=if ([$Title] == '', 'New Item', 'Software Name: ' + [$Software Name])"
                }
            ]
        }
    ]
}

@leonardbd You have to use the internal name of software name column in JSON.

 

You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?  

 

If internal name is SoftwareName then use [$SoftwareName].


Please consider giving a Like if my post helped you in any way.

Hi Ganesh, unfortunately it didn't work. I found the internal name by following your resource.

@leonardbd Is it a single selection choice column or multiple selection choice column? Can you show us the screenshot of internal name of column you found and how you are using it in JSON now?

 

Also, this column should be available on list form in order to reference it in the SharePoint JSON form formatting.


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.

1 best response

Accepted Solutions
best response confirmed by leonardbd (Copper Contributor)
Solution

@leonardbd Use .title instead of .DisplayName. I just tested and it is working fine for me. Also, make sure you are using correct internal name of your people picker column in JSON. You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?  

 

{
    "elmType": "div",
    "attributes": {
        "class": "ms-bgColor-green"
    },
    "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": "MobileSelected",
                        "class": "ms-fontSize-42 ms-fontWeight-regular  ms-fontColor-white",
                        "title": "Software Name"
                    },
                    "style": {
                        "flex": "none",
                        "padding": "0px",
                        "padding-left": "0px",
                        "height": "36px"
                    }
                }
            ]
        },
        {
            "elmType": "div",
            "attributes": {
                "class": "ms-fontColor-white 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 ([$Title] == '', 'New Item', 'Request of: ' + [$Requestor.title])"
                }
            ]
        }
    ]
}

 


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.

View solution in original post