Share via

Trying to get a column formatting code to pull out a part of a filename

Anonymous
2024-07-05T03:41:45+00:00

I have a number of SharePoint 365 libraries that contain files named like this "xxxxxx.txt.url or xxxxx.docx.url but ther are also normally named files that are just named xxxxxx.xlsx ect. I am attempting to write a JSON script within SharePoint 365 column formatting to pick out and display the fist file extension so from the first example just txt and drop the .url and from the second example xlsx ect.

Here's what I have been trying but it just won't work for some reason:

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": { "operator": "+", "operands": [ "=if(indexOf([$FileLeafRef], '.url') != -1, substring([$FileLeafRef], indexOf([$FileLeafRef], '.') + 1, indexOf([$FileLeafRef], '.url') - indexOf([$FileLeafRef], '.') - 1), substring([$FileLeafRef], indexOf([$FileLeafRef], '.') + 1))", "" ] } }

Please let me know what I'm doing wrong.

Thank you in advance

Microsoft 365 and Office | SharePoint | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-07-05T06:39:55+00:00

    Dear Andrewmatson,

    You can see whether the following code works in your environment.

    {

    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",

    "elmType": "div",

    "txtContent": "=if(indexOf('@currentField','url') > 0,substring('@currentField',0,indexOf('@currentField','url')-1),'@currentField')"

    }

    Thanks for your effort and time.

    Sincerely

    Cliff | Microsoft Community Moderator

    Was this answer helpful?

    0 comments No comments