Louis-Charles Gagnon

Microsoft Azure, Office 365 and SharePoint Blog

SharePoint 2013 - Fix Lookup column not linking to a list

Sometimes after deployment or data manipulation, a list is left not connected to a list.

With powershell you can fix individual column to update it's lookup list:

 Function Fix-LookupColumn ($webURL, $listName, $columnName, $lookupListName)
     #Get web, list and column objects
     $web = Get-SPWeb $webURL
     $list = $web.Lists[$listName]
     $column = $list.Fields[$columnName]
     $lookupList = $web.Lists[$lookupListName]
     #Change schema XML on the lookup column
     $column.SchemaXml = $column.SchemaXml.Replace($column.LookupWebId.ToString(), $web.ID.ToString())
     $column.SchemaXml = $column.SchemaXml.Replace($column.LookupList.ToString(), $lookupList.ID.ToString())
     #Write confirmation to console and dispose of web object
     write-host "Column" $column.Title "in list" $list.Title "updated to lookup list" $lookupList.Title "in site" $web.Url

In order to use this function, simply call the following:

Fix-LookupColumn -webURL <URL> -listName "<List name containing the lookup column>" -columnName "<Lookup column name>" -lookupListName "<List used by the lookup column>"

For example:

Fix-LookupColumn -webURL http://mysite/site -listName "Clients" -columnName "Company" -lookupListName "Company"

blog comments powered by Disqus