0

I am using 2 metadata-columns in my SharePoint-List: "Created By" and "Change By". In these columns a name appear of the person who has created or changed the List-item. I would like to have a picture with it. Like the column Person has.

I have used JSON-code but it doesn't seem to work.

Is it even possible?

enter image description here

"Gemaak door" means "Created By".

1
  • I will suggest you try running this URL in your browser & see if it works: <siteUrl>/_layouts/15/userphoto.aspx?size=S&accountname=<email-address> – Ganesh Sanap Mar 1 at 8:36
1

Please add below Json code in the "Created By" and "Modified By" columns.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "div",
      "style": {
        "width": "32px",
        "height": "32px",
        "overflow": "hidden",
        "border-radius": "50%"
      },
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "='/_layouts/15/userphoto.aspx?size=S&accountname=' + @currentField.email",
            "title": "@currentField.title"
          },
          "style": {
            "position": "relative",
            "top": "50%",
            "left": "50%",
            "width": "100%",
            "height": "auto",
            "margin-left": "-50%",
            "margin-top": "-50%"
          }
        },
        {
          "elmType": "span",
          "txtContent": "@currentField.title"
        }
      ]
    }
  ]
}

enter image description here

3
  • Strange what ever i do it still does not work :( – user2170776 Mar 1 at 9:04
  • I have updated the Json code. Please check. – Emily Du - MSFT Mar 1 at 9:13
  • The code does not show my picture – user2170776 Mar 1 at 11:11
0

If you are talking about SharePoint default "Created By" & "Modified By" columns, it is possible to format this columns using JSON.

I have used the same JSON code in your previous question and it is working fine for me, adding the same code here for reference:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "flex-direction": "column",
    "align-items": "flex-start",
    "margin-top": "6px",
    "padding-right": "8px",
    "width": "100%",
    "overflow": "hidden"
  },
  "children": [
    {
      "forEach": "personIterator in @currentField",
      "elmType": "div",
      "attributes": {
        "class": "ms-bgColor-neutralLight ms-fontColor-neutralSecondary"
      },
      "style": {
        "display": "inline-flex",
        "align-items": "center",
        "height": "28px",
        "overflow": "hidden",
        "border-radius": "12px",
        "padding-right": "8px",
        "margin": "2px"
      },
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "='/_layouts/15/userphoto.aspx?size=S&accountname=' + [$personIterator.email]",
            "title": "[$personIterator.title]"
          },
          "style": {
            "width": "28px",
            "height": "28px",
            "display": "block",
            "border-radius": "50%"
          }
        },
        {
          "elmType": "div",
          "txtContent": "[$personIterator.title]",
          "attributes": {
            "title": "[$personIterator.title]",
            "class": "nameplate-title"
          },
          "style": {
            "padding-left": "5px",
            "white-space": "nowrap",
            "font-size": "12px"
          }
        }
      ],
      "defaultHoverField": "[$personIterator]"
    }
  ]
}

Output:

enter image description here

Note: This code is for multiple selections of users. It works for both single/multiple selections. But if you want, you can convert it for single selection only.

You can find other supported/unsupported columns in JSON formatting at Microsoft documentation: Column formatting - Supported column types


If this above approach is not working for you then you can try using below in src property of img element (instead of creating image URL on your own):

personIterator.picture

As person or group column in JSON supports below properties at this time (sample data):

{
   "id": "122",
   "title": "Kalya Tucker",
   "email": "kaylat@contoso.com",
   "sip": "kaylat@contoso.com",
   "picture": "https://contoso.sharepoint.com/kaylat_contoso_com_MThumb.jpg?t=63576928822",
   "department":"Human Resources",
   "jobTitle":"HR Manager"
}

Source: Column formatting - Special string values

2
  • Frustrating :( Nothing works. I have a feeling we are looking at the wrong direction. Everything i do nothing works. What am i missing? You show me that it is works and what ever i do nothing works – user2170776 Mar 1 at 10:30
  • When I just adjust for the column Person to show picture without JSON code. It works but I get the pictures smaller. And when i use JSON-code in the "Modify by" column i get a bigger place holder but no picture. In the snapshot that i have posted at the beginning of this question you can see the difference in size very good. – user2170776 Mar 1 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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