1

I'm currently using SharePoint column formatting JSON to turn a field's string entry into a URL using the following:

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

Since @currentField contains a filename.pdf (file size) I will end up with broken link were the file size is included in the link, something like http://finance.yahoo.com/quote/my-file-name_pdf.pdf%20(338%20KB) Can I generate a link which ends with *.pdf or space?

1
  • Hi @Omal, does this answer help you in any way? If yes, please Upvote(^) and accept as an Answer as it helped you & it will help others with similar question in future to find the correct answer easily. Commented Mar 16, 2023 at 14:13

1 Answer 1

0

If you don't have any space in filename.pdf, you can use the expression like below to extract the filename before space between file name & file size:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
     "target": "_blank",
     "href": "='http://finance.yahoo.com/quote/' + substring(@currentField, 0, indexOf(@currentField, ' '))"
  }
}

OR:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
     "target": "_blank",
     "href": "='http://finance.yahoo.com/quote/' + substring(@currentField, 0, indexOf(@currentField, ' ('))"
  }
}

Documentation: Formatting syntax reference

1
  • Hi @Omal, does this work for you? Commented Apr 5, 2022 at 14:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.