Forum Discussion

leonardbd's avatar
leonardbd
Copper Contributor
Sep 04, 2023

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

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. 

 

  • 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 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: 


    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's avatar
      leonardbd
      Copper Contributor

      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])"
                      }
                  ]
              }
          ]
      }

Resources