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 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? Apr 5 at 14:02

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.