SOLVED

JSON column formatting - get user's phone number from people column

Brass Contributor

In a SharePoint list (M365), I have a people column.  Even though the contact information is already included in the people column, users still want it displayed as separate columns.  I used JSON formatting to grab the email address using [$ContactPerson.email] but I cannot figure out how to grab the phone number.  I tried [$ContactPerson.businessphones], .telephonenumber, .phones but didn't work. 

As a work around, I just used Power Apps and default value:

Substitute(Substitute(Substitute(First(Office365Users.UserProfileV2(DataCardValue2.Selected.Email).businessPhones).Value, "(", ""), ")", ""), " ", "-")



Here's the code, I'd like to change the @currentField in line 22 to grab the phone# from [$ContactPerson]. 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "block",
        "color": "#333333",
        "text-align": "left",
        "font-size": "16px",
        "font-weight": "bold",
        "padding-top": "10px",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "Phone"
      }
    },
    {
      "elmType": "a",
      "txtContent": "@currentField",
      "attributes": {
        "target": "_blank",
        "href": "='https://teams.microsoft.com/l/call/0/0?users=' + [$ContactPerson.email]"
      }
    }
  ]
}

 

1 Reply
best response confirmed by Tamras1972 (Brass Contributor)
Solution

@Tamras1972 Unfortunately, SharePoint JSON formatting does not support fetching phone number of users from person or group columns. It only supports below properties(with example values): 

 

 

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

 

 

So, try this:

  1. Create a new column for phone/contact number
  2. Customize list form using Power Apps and update the phone/contact number automatically from Power Apps based on user selection in people field - using the formula you posted above
  3. Then apply JSON column formatting like below for you for phone/contact number: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "block",
        "color": "#333333",
        "text-align": "left",
        "font-size": "16px",
        "font-weight": "bold",
        "padding-top": "10px",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "Phone"
      }
    },
    {
      "elmType": "a",
      "txtContent": "@currentField",
      "attributes": {
        "target": "_blank",
        "href": "='https://teams.microsoft.com/l/call/0/0?users=' + @currentField"
      }
    }
  ]
}
​

 


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 Tamras1972 (Brass Contributor)
Solution

@Tamras1972 Unfortunately, SharePoint JSON formatting does not support fetching phone number of users from person or group columns. It only supports below properties(with example values): 

 

 

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

 

 

So, try this:

  1. Create a new column for phone/contact number
  2. Customize list form using Power Apps and update the phone/contact number automatically from Power Apps based on user selection in people field - using the formula you posted above
  3. Then apply JSON column formatting like below for you for phone/contact number: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "block",
        "color": "#333333",
        "text-align": "left",
        "font-size": "16px",
        "font-weight": "bold",
        "padding-top": "10px",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "Phone"
      }
    },
    {
      "elmType": "a",
      "txtContent": "@currentField",
      "attributes": {
        "target": "_blank",
        "href": "='https://teams.microsoft.com/l/call/0/0?users=' + @currentField"
      }
    }
  ]
}
​

 


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