July 17, 2012

SharePoint 2010 Custom List: Duplicate Columns with Same ID!

Background

I have a SharePoint 2010 site with a custom list (build in Visual Studio with a custom content type). This site has been migrated from SharePoint 2007.

Issue

After the migration, I noticed that the list has duplicate fields:

image

Looking at the content type, I can see that there are duplicate fields in there:
782fda9b-db6f-4f19-9e4a-2eefe8bd49e0    ParentFolder
7fb88270-d7cb-45b0-9fd1-5118b6441587  FolderPath
7fb88270-d7cb-45b0-9fd1-5118b6441587  FolderPath
d5a17075-45bf-4ef5-83dd-057d771755cb  SortOrder
d5a17075-45bf-4ef5-83dd-057d771755cb  SortOrder

The weird thing is that the content type has Field links with the same ID and internal name, how is that even possible?!!

Trying to hide one of the fields hides both, what the heck!

Solution

After a few failed tries, I decided to delete the FieldLink in the content type and readding them, so I used PowerShell:

$web = Get-SPWeb http://gtnahoui948/fg/cmg
$list = $web.Lists["Contract Structure"]
$cType = $list.ContentTypes["Folder Structure Item"]
$cType.FieldLinks.Delete("FolderPath")
$cType.Update()
$cType.FieldLinks.Delete("SortOrder")
$cType.Update()


After running the above code in PowerShell, I checked the FieldLinks and found out it only deleted the duplicates and kept one instance in the FieldLinks, Awesome!


782fda9b-db6f-4f19-9e4a-2eefe8bd49e0    ParentFolder
7fb88270-d7cb-45b0-9fd1-5118b6441587  FolderPath
d5a17075-45bf-4ef5-83dd-057d771755cb  SortOrder


That being said; no need to add the links again Smile

No comments:

Post a Comment