0

Simple question so it seems, but I'm trying to set the Title value of a doc library base on the File Name in the column Formatter.

Is this possible?

The source below gets wiped out from the Title field after I save.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "="[$FileLeafRef]"
}

Ideally I would like to remove the file extension as well. I assume String.split() would be necessary?

Thanks.

2
  • There is extra a " after = in txtContent property, try removing it. Nov 16 at 2:36
  • Hi @Beruken, did you try solution given below? Is it working for you? Nov 27 at 13:21

1 Answer 1

1

I am able to reproduce this issue on our SharePoint site. Here are the results:

  1. I am unable to see the Format this column option to SharePoint default "Title" column in the document library (Title column is added to view using classic experience view settings page):

    enter image description here

  2. I opened the Title column settings from list settings page, added the JSON formatting and saved the column settings. But when I opened the Title column settings again, the JSON was automatically removed from there:

    enter image description here

  3. I tried settings custom JSON column formatting for this field using PnP PowerShell as well but it didn't work.

Maybe there is some limitation or bug for the SharePoint default Title column in the document library (it is a site column inherited from "Item" content type). You can raise a support ticket with Microsoft directly and report this behavior at: Get M365 Support - Online


Meanwhile, you can try this workaround:

  1. Create a new column in your document library.
  2. Apply JSON column formatting for this new column. Use this JSON:
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(indexOf([$FileLeafRef],'.')>-1,substring([$FileLeafRef],0,lastIndexOf([$FileLeafRef],'.')),[$FileLeafRef])"
}

Where FileLeafRef is the internal name of SharePoint default "Name" column in document libraries. You can get the exact internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

Output:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.