SharePoint library/folder default field values

You can configure default values on a SharePoint library (root folder) or library folder fields. For example, if you configure default values in a folder, documents added to that folder will automatically inherit those field values. This functionality is great when you have a project that heavily relies on metadata. Especially if metadata should be inherited through multiple levels of information.

Setting default field values via the SharePoint interface

You can configure default values via the List Settings page under “Column default value settings” as per the following image

In the following example, I have configured my test list fields with default values. The “Active document” field has a default value of “Yes” at the list level.

I then set a default value on the field to “No” for “Folder 1” within the library. Folders configured with custom default values are displayed with a green icon on the settings page.

While this option to manually set the values is easy for an end user, it is not practical for complex scenarios where some automation may be required.

Setting default field values using PnP PowerShell

PnP PowerShell is always my go-to option when I need to set configurations in some automated way. With a super simple Set-PnPDefaultColumnValues command, you can set the default values of any folder (including the root folder). It also makes it very easy to work with complex fields, like managed metadata or user fields.
Just as an example, the following command (from the documentation) is to set a managed metadata field

Set-PnPDefaultColumnValues -List Documents -Field TaxKeyword -Value "Company|Locations|Stockholm"

Default fields configuration

While working on a client project, I faced an unexpected issue with default field values. Suddenly, the PnP PowerShell command to set the default values started throwing errors. The same piece of code that was working for some days to set multiple fields with default values. It was now returning a message stating that field XXXXXX was no longer available in the list.

I deleted a test field on the list and commented the line of the script where I was setting that field. I could see no reason for a script error relating to that field as the line was commented out.
Checking the default fields configuration in the list settings page also didn’t provide any useful information. Everything seemed to be working fine there.
I then decided to find the place where the configuration is stored. It was likely the cause of my issues.
After some search, I was quite surprised with what I found! The default field value configurations are stored as a client_LocationBasedDefaults.html file. Within the Forms folder of the document library where they are configured.

Why you may need to know this?

Back to using the sample list from the previous steps above, this can be easily checked using SharePoint Designer. And for the custom test field that I have previously set, we can see that the HTML file contains a reference for it.

In my case, the issues were down to the field that was removed from the list and had default values configured against some folders in the library. Deleting the field did not remove its reference from the client_LocationBasedDefaults.html file, and the PowerShell command was then failing when trying to set values on other fields for that folder. Deleting and recreating the folder also didn’t resolve the problem, so at the end it was just down to editing the HTML file and remove the references to the field previously deleted from the list. And “voila”, the PowerShell command was working again.

2 Replies to “SharePoint library/folder default field values”

    1. Hi vijay,
      Sorry for the late reply…
      It’s possible to retrieve via PnP.PowerShell, so behind the scenes that command is likely using CSOM. Have a look at how the command is implemented and you may be able to reuse the same code

Leave a Reply

Your email address will not be published. Required fields are marked *