1

I have a simple JSON formatting code for a column in SharePoint in order to redirect to the appropriate target depending on the content of the record.

Here is the code:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
        "href": "=IF(LEFT(@currentField,3)=='INC', 'https://domain.service-now.com/nav_to.do?uri=incident.do?sysparm_query=number=' + @currentField, IF(LEFT(@currentField,3)=='PRB', 'https://domain.service-now.com/nav_to.do?uri=problem.do?sysparm_query=number=' + @currentField, 'https://domain.atlassian.net/jira/software/c/projects/CCE/issues/' + @currentField))",
"target": "_blank"
  }
}

The format is accepted by SharePoint, but the output is blank. So I'm a bit stunned.

And the simple code is working like a charm:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='https://domain.service-now.com/nav_to.do?uri=incident.do?sysparm_query=number='+ @currentField"
  }
}

Thanks in advance for any help on this.

1
  • Try JSON given in my answer below. Let me know if it works for you or if you face any issues while using it. Nov 29, 2023 at 18:49

1 Answer 1

0

LEFT() function is from SharePoint calculated column formulas which is not supported in SharePoint JSON formatting.

Use below JSON column formatting:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "href": "=if(substring(@currentField,0,3)=='INC', 'https://domain.service-now.com/nav_to.do?uri=incident.do?sysparm_query=number=' + @currentField, if(substring(@currentField,0,3)=='PRB', 'https://domain.service-now.com/nav_to.do?uri=problem.do?sysparm_query=number=' + @currentField, 'https://domain.atlassian.net/jira/software/c/projects/CCE/issues/' + @currentField))",
    "target": "_blank"
  }
}

You can also refer column values in JSON in the format [$MyColumnName] instead of @currentField. Where MyColumnName is the internal name of your SharePoint list column.

You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

Output:

enter image description here

3
  • You can use either substring or startsWith operator for such requirements. Nov 29, 2023 at 18:49
  • 1
    Waouh. you're awesome. SO powerful § it works like a charm. Thank you so much !
    – Brucks
    Nov 30, 2023 at 19:55
  • You are welcome, I am glad it worked for you! Keep using this platform to ask any questions related to SharePoint. Dec 1, 2023 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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