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. 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

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.