0

I'm currently using MS's column formatting JSON to turn a field's string entry into a URL using the following to automatically make the ticket number entry a clickable hyperlink to our zendesk for the respective ticket number:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='https://URLANONYMIZED.zendesk.com/agent/tickets/' + @currentField"
  }

However, if we have multiple tickets for the same issue, it would be nice to be able to do the same for multiple values that are separated by a space, comma, or what have you so that each ticket number would link to it's respective ticket. Is this possible? Using Office 365 hosted sharepoint if that matters any.

0

You can use the below and further customize as needed.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "forEach": "choiceIterator in @currentField",
      "elmType": "a",
      "txtContent": "[$choiceIterator]",
      "attributes": {
        "target": "_blank",
        "href": "='https://URLANONYMIZED.zendesk.com/agent/tickets/' + [$choiceIterator]"
      },
      "style": {
        "width": "100px",
        "height": "16px",
        "text-align": "center",
        "padding": "5px",
        "margin": "1px"
      }
    }
  ]
}

enter image description here


Updating to show how to create hyperlinks for [Single line of text] column containing comma, space, or both separated string

Example of string: 34567, 56789, 56789 is separated by a comma(,) and a space.

The JSON needs to be adjusted if there are more than 3 ticket numbers and the number of chars separating them is not 2 (a comma and a space)

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "a",
      "style": {
        "padding": "5px",
        "display": "=if(indexOf(@currentField + '^', '^')>4,'flex', 'none')"
      },
      "txtContent": "=substring(@currentField, 0, 5)",
      "attributes": {
        "target": "_blank",
        "href": "='https://URLANONYMIZED.zendesk.com/agent/tickets/' + substring(@currentField, 0, 5)"
      }
    },
    {
      "elmType": "a",
      "style": {
        "padding": "5px",
        "display": "=if(indexOf(@currentField + '^', '^')>11, 'flex', 'none')"
      },
      "txtContent": "=substring(@currentField, 7, 12)",
      "attributes": {
        "target": "_blank",
        "href": "='https://URLANONYMIZED.zendesk.com/agent/tickets/' + substring(@currentField, 7, 12)"
      }
    },
    {
      "elmType": "a",
      "style": {
        "padding": "5px",
        "display": "=if(indexOf(@currentField + '^', '^')>18, 'flex', 'none')"
      },
      "txtContent": "=substring(@currentField, 14, 19)",
      "attributes": {
        "target": "_blank",
        "href": "='https://URLANONYMIZED.zendesk.com/agent/tickets/' + substring(@currentField, 14, 19)"
      }
    }
  ]
}

Before applying JSON

enter image description here

After applying JSON

enter image description here

6
  • This field is a Single Line of Text field that users can manually add entries to. This seems to be for a choice field, which while valid, completely blanks out any entries in my test form. – James Oct 21 '20 at 17:53
  • Sorry, I misunderstood. What is the format of the text, that's, are the values separated with a space char or something else? – Matiur Rahman Oct 21 '20 at 18:30
  • No worries! The string is just a 5 digit number. I can have them separated by a comma or a space. I'll just instruct my users to use that format. Right now, I'm just instructing them to use one ticket, but I wanted to see if doing multiple tickets was possible. – James Oct 21 '20 at 19:59
  • I think we can do it. Please see my updated post and let me know if you have any questions. As I've mentioned, you need to adjust if you expect more than 3 tickets numbers and if the number of chars separating the ticket numbers NOT 2. In the example, I'm using a comma and a space (2 chars) – Matiur Rahman Oct 22 '20 at 15:01
  • That worked! So long as the ticket number length stays 5 digits, this should last for a while. Thank you very much for the help! – James Oct 22 '20 at 16:57

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.