Forum Discussion
How to Properly Delete Custom Columns in SharePoint
SharePoint custom columns have been around for quite some time, but I’m finding that there’s still some confusion on how the various types are used, and more importantly how can you delete them. In this post, I’m hoping to shed some light on the topic.
Custom columns form a part of your overall SharePoint Information Architecture. When properly set up, custom columns (or fields as sometimes referred to in SharePoint) are ideal for capturing metadata in a consistent way across various types of content. In SharePoint, you can create custom columns in one of two ways:
Custom List Column
Custom List columns are created directly within a list (or library). They can be accessed via the list and used to store information. Although quick to set up, one of the major drawbacks is that list columns are limited in scope to only the list in which you created them. You cannot leverage the site columns outside of the list. This reason alone can prevent such columns from being considered for scalable solutions where you would have to add the same columns to multiple lists or libraries throughout a SharePoint site.
Custom Site Columns
Custom Site columns, as their name suggests, are created at the site level. Unlike their List Column relatives, the Site columns are accessible throughout the entire site collection, where you can add them to any number of lists, libraries, and content types. When you change the Site column properties, you have the choice to propagate these changes to all instances where the Site column is in use.
Deleting Custom Columns
If you wish to remove a custom column, it’s important to understand your options and the ramification they have on your data as described below.
Deleting a List Column
As I’ve mentioned earlier, when you create a new column within a list or library (not selected from pre-existing site columns), the list owns the column, and the column is only accessible to the list. Therefore, you can easily delete it from the List Settings by selecting the column and then clicking the Delete button on the form.
Keep in mind that once you delete the list column, you also lose any data associated with the column.
Deleting a Site Column from a List
A reference to the site column is added when you add a site column directly to a list. As mentioned above, whenever you change the site column, any instances that use it will change as well. In the example below, I’m showing a Date field that has been added directly to two lists.
If you try and delete the Date site column, you will see a warning message similar to
This site column will be removed and all list columns which were created from it will be permanently orphaned. Are you sure you want to delete this site column?
What does orphaned mean? Well, think of the site column as being the parent that controls its children (the referencing site columns within the lists). They will behave as their parent does. When you delete the parent, then you are in essence converting the site columns within the lists into list columns that lose the relationship between them. In other words, each list will have its unique copy of the site column with all the same settings just before you deleted the site column. You cannot undo this change.
Deleting a Site Column from a Content Type
When you add a site column to a content type, you’re following better practices for your Information Architecture by encapsulating all required metadata into a reusable entity (content type) rather than dealing with the individual site columns in each list. On the flip side, deleting your site column now becomes a bit trickier. If you tried to remove a site column that is associated with a content type, you might have seen a message as
Site columns which are included in content types cannot be deleted. Remove all references to this site column prior to deleting it.
What you need to do in this case is remove the site column from each content type before removing it. But what do you do if you don’t know where it’s used? In this case, you can leverage PowerShell to help you get the answer you need. To find out what content types are using your site column, you first need to know the InternalName of your site column. You find it by going to the site column (Site Settings à Site Columns) and looking at the URL as depicted below.
In my case, the field is called Date1. Now you can run the script below that is based on OfficeDev PnP to search all the content types in a site collection. The script lists all the content types that use the site column you wish to delete (NOTE: to run the code I’ve supplied below, you must install the OFficeDev PnP solution first from https://github.com/OfficeDev/PnP-PowerShell).
Connect-Sponline -url "your_tenant_url" $fieldInternalName = "your_field" $web = Get-SPOWeb Write-Host "Searching for:" Write-Host "InternalName: $fieldInternalName" Write-Host Write-Host "Get Content Types" $cTypes = Get-SPOContentType | where {($_.Hidden -eq $False) -and ($_.Group -ne "_Hidden")} # Search through all the non-hidden content type and find which ones include the site column foreach($ct in $cTypes) { $fields = $ct.Fields $web.Context.Load($fields) $web.Context.ExecuteQuery() $field = ($fields | where {$_.InternalName -eq $fieldInternalName}) if ($field -ne $null) { Write-Host "Content Types: $($ct.Name)" Write-Host "Content Type ID: $($ct.ID)" } }
The output will look something similar to the image below.
Searching for: InternalName: Date1 Get Content Types Content Types: TestCT Content Type ID: 0x01010038A3F80D4105C845BDD6A523CB1CC969
Now you need to go to the Content Types (Site Settings à Site Content Types) and look for the content types by name. If you see any duplicates, compare the content type ID against the one listed in the URL.
Just remember, removing the columns from the content type will delete the content of those columns.
That’s it. Now you know what to look for when removing your custom columns. Good luck.
13 Replies
- BstevensonCopper Contributor
Haniel Croitoru This is great info. One question. How do you remove the orphaned list column from the individual sites? Is there a way to do that with powershell or sharepoint designer or do you have to go to each individual site and remove it manually?
- Ian MoranIron ContributorIt's a pity that modern doc libraries and lists make it so easy to add "list" columns
- Haniel CroitoruLearn Expert
Pitty indeed. You can, of course, always set up a specific group for users and only give them Contribute access so they can't modfiy the structure. But that's a pain.
- William HardwickIron ContributorGood advise, I just had a user create a bunch of columns that I had to unravel.
- William HardwickIron ContributorI suggest creating them in the Content Type Hub. But be prepared for a long wait after publishing! That's if your using SharePain online. That's one downfall to it, but the benefits out weigh the cons.
- Lynley HippsBrass Contributor
Great article, Haniel Croitoru! I especially love the PowerShell trick - we have some *very* old site collections that I've attempted to clean up, but so many poorly architected sites and content types just stymied me. I will definitely leverage PowerShell next time! Thanks!
- Anna-Maria KähkönenIron Contributor
Great post, good basic information for someone who has not used SharePoint for long.
- Dean_GrossSilver ContributorWhile there is a lot of good information in this article, it fails to mention a common problem that occurs when a Site column is created in a lower level of a site collection, the column is not available to the parent sites nor in the sibling sites. This can lead to a tremendous amount of confusion if another column is added to the top of the collection.
I strongly recommending creating all site columns at the root of the site collection- William HardwickIron ContributorGood advise, and one should create them in the content type hub first, correct?
Or no?- Dean_GrossSilver Contributor
It really depends on the scope of usage and your need to control deployment. Anything in the CT hub will show up "everywhere" and in SPO you don't have any control over when the changes in the CT hub get pushed out.
Just like almost everything in SP, the "best practice" has caveats and exceptions :)
- Lynley HippsBrass ContributorYou are so right, Dean - I learned this the hard way! Plus, for me it's just easier to manage. However, if you have a site admin who wants to use site columns but doesn't have site collection admin rights, you'll have to do some permission tweaking to allow them to create them at the root level. Or you can do it yourself :)
- Haniel CroitoruLearn Expert
Dean_Gross, you're absolutely right. Creating site columns in subsites is a common poor practice. My goal with this short article was to focus on issues commonly faced when deleting existing columns. Appreciate your feedback! :smileyhappy: