1

In a list I used column formatting to display a user's profile picture by building a url to the image like this:

"elmType": "img",
      "attributes": {
        "src": "='/_layouts/15/userphoto.aspx?size=L&username=' + [$iNumber] + '@xxx.com'",
        "title": "@currentField" 

Where "$iNumber" is the employee's id in a single line of text field (cannot use a people field in this case). Now I want to apply view formatting to improve the entire view, and tried this:

"elmType": "img",
                "attributes": {
                  "src": "=@currentWeb + '/_layouts/15/userphoto.aspx?size=L&username='+ [$iNumber] + '@xxx.com'"

And this using an operator for the url:

"operator": "+",
                "operands": [
                    "/_layouts/15/userphoto.aspx?size=L&username=",
                    "[@iNumber]",
                    "@xxx.com"
                ]

The output when I inspect the element for either is:

src="/_layouts/15/userphoto.aspx?size=L&username=' + [@iNumber] + '@xxx.com'"

So the field value isn't getting pulled in. Is this a formatting error or is it because there's a conflict between the column and view formatting?

  • Try changing [@iNumber] to [$iNumber] ? – Rune Sperre Apr 9 at 17:06
  • What is stored in [$iNumber] filed? User email? – Ganesh Sanap Apr 9 at 17:11
0

You need to use user email address to get the profile picture. Below is the generic format to get the profile picture of user:

 "elmType": "img",
 "attributes": {
      "src": "='/_layouts/15/userphoto.aspx?size=S&accountname=' + <user email address>"
 }

Replace <user email address> with user email address.

Sample Example:

GitHub - person-roundimage-format

Note: To refer another column in JSON formatting you need to use it in below format - [$InternalNameOfColumn]

Source: SharePoint JSON formatting - Refer another column

| improve this answer | |
  • Actually I am using the email address (inumber@xxx.com) and the images work but my suspicion about column formatting overriding the view format was correct. I removed the column format and it started working - on another view though (which is stil very odd). – matt Apr 9 at 18:02
  • Yes, column formatting overrides view formatting. If you have applied any column formatting in same view then you need to remove it or create a new list view and add view formatting there. – Ganesh Sanap Apr 9 at 18:20
  • Hi @matt, does this answers your question? If Yes, Please Upvote(^) and accept as an Answer so that it will help others in future to find the correct answer easily. – Ganesh Sanap May 15 at 9:11
  • Column Formatting does not override view formatting. It is the opposite. Column Formatting can be used in conjunction with View formats that use the rowClass attribute. But when using the rowFormatter attribute, column formats are ignored. – theChrisKent Sep 27 at 16:44

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.