Automatically add site column to new libraries
Category
- [x] Question
- [ ] Typo
- [ ] Bug
- [ ] Additional article idea
I need to deploy a custom column "classification" to all site collections and libraries, that will be created in the future. The column should be a choice or managed metadata column.
What approach to achieve this would you suggest?
I thought of creating a site design, which adds the column as a site column and adds this site column to the Document content type (0x0101). Is this possible with site designs? I only found documentation on how to create new content types, not on how to alter default ones. Should I even alter the default document content type at all? What are potential drawbacks and challenges?
I would love to get some input on this topic.
Modifying the OOTB content types is not something you should ever do. If you own the provisioning process of new sites, you could add a ListAdded remote event receiver (there is no webhook available yet) to your site and add your column in this event. Another way would be to create a tenant wide SPFx extension, register it on list template 101 and check if your column was added to the list and add it if needed. All would be running in the context of the current user that accesses the library.
Hi Oliver, thanks for the reply. I expected something like this. It's a bummer that there are no Site scoped webhooks implemented yet. As this would a solution to implement some kind of governance, I'm a bit hesitent to implement this as an SPFx extension. In such a scenarion the extension would be loaded each time a user accesses a library, although the user might not even have the permissions to alter something.
So from what I know today, the setup would look somewhat like this:
- Add a default site design, which adds the remote event receiver on every new site. This probably will only trigger a flow, which triggers an azure function.
- Configure a remote event receiver that listens to the ListAdded event, and adds a predefined column to every newly created library.
This should work, yes. But I would still think again about the extension. This solution would be more future proof the way I see it. Especially it would give you the option to update existing Libraries if your requirements change later on. The ListAdded Event will trigger only once and thats it. Updating existing sites e.g. via a script requires that you have access to all existing sites later. This may not always the case, so that is something you should consider upfront. Also you can check the permissions of the current user in your extension and just do nothing if the user does not have the correct permissions to alter something. But as said earlier, both ways should help solve the requirement.
Hi Oliver & @VesaJuvonen,
Thanks for the guidance above.
With regards to this discussion and this specific comment:
Modifying the OOTB content types is not something you should ever do.
Are you able to point to some guidance or expand on why this is bad and something you should never do?
Thanks in advance Pete
This issue is being closed as part of an issue list cleanup project. Issues with no activity in the past 6 months that aren't tracked by engineering as bugs were closed as part of this inititive. If this is still an issue, please follow the steps outlined to re-open the issue.