SharePoint JSON formatting - tel: protocol

Volesini Matej 20 Reputation points
2023-01-23T11:46:07.1466667+00:00

Hello,

It seems the tel: protocol is now available ([https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#create-clickable-actions)

Does anyone have an idea on how to write the correct JSON for this?

My column settings in SharePoint list are for a single line of text as I would like to be able to include special characters and visual separators.

Thanks,

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Xyza Xue_MSFT 30,176 Reputation points Microsoft External Staff
    2023-01-24T06:59:47.9566667+00:00

    Hi @Volesini Matej ,

    For example, I created a single line of text column, when an e-mail address is entered, I would like the column to display a clickable mailto: link. When a phone number is entered, I would like it to be formatted (000) 000-0000.The display effect is as follows( You can change the JSON according to your specific needs):

    User's image

    You can use following JSON:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
      "elmType": "div",
      "children": [
        {
          "elmType": "a",
          "style": {
            "padding-right": "8px",
            "display": "=if(indexOf(@currentField,'@') > -1, 'block','none')"
          },
          "txtContent": "@currentField",
          "attributes": {
            "target": "_blank",
            "href": {
              "operator": "+",
              "operands": [
                "mailto:",
                "@currentField"
              ]
            }
          }
        },
        {
          "elmType": "span",
          "style": {
            "overflow": "hidden",
            "text-overflow": "ellipsis",
            "padding": "0 3px",
            "display": "=if(indexOf(@currentField,'@') > -1, 'none','block')"
          },
          "txtContent": "=if(indexOf(@currentField + '^', '^') == 10,'('+substring(toString(@currentField),0,3)+') '+substring(toString(@currentField),3,6)+'-'+substring(toString(@currentField),6,10),if(indexOf(@currentField + '^', '^') == 7,substring(toString(@currentField),0,3)+'-'+substring(toString(@currentField),3,8),@currentField)",
          "attributes": {
            "class": ""
          }
        }
      ]
    }
    
    

    Reference Link: https://sharepoint.stackexchange.com/questions/303082/json-to-make-a-sharepoint-list-column-accept-a-phone-number-and-or-an-e-mail-add


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.