A story from real life. There was a list to store many elements which were basically used for some other lists by using lookup columns. After this big important list was deleted and recovered from backup, the connection between the lookup column and the lookup list ist broken. The column does not show any entries nor can it be repaired using the UI.
Normally it displays that it gets its information from List X, but this is empty. What happened?
The lookup column is always connected by some properties:
- WebId – This is the web where the list is stored
- ListId – This is the List where the information comes from
- ShowField – This is the field from source list, which will be displayed
After backup the listId is broken, maybe the WebId too. Therefore the following powershell script could be very useful. But keep in mind, that you have to decide between a list column with lookup and site column with lookup.
Fix List Column with lookup
$webURL = "http://server/sites/XY" $listName = "MyList" $columnName = "MyColumn" $lookupListName = "Category" $lookupWebURL = "http://server/sites/X" RepairListLookupColumns -webURL $webURL -listName $listName -columnName $columnName -lookupListName $lookupListName -lookupWeb $lookupWebURL Function RepairListLookupColumns($webURL, $listName, $columnName, $lookupListName, $lookupWebURL) { #Get web, list and column objects $web = Get-SPWeb $webURL $lookupWeb = Get-SPWeb $lookupWebURL $lookupWeb = Get-SPWeb $lookupWebURL $list = $web.Lists[$listName] $column = $list.Fields[$columnName] $lookupList = $lookupWeb.Lists[$lookupListName] $newLookupListID = "{"+$lookupList.ID.ToString()+"}" $newLookupWebID = "{"+$lookupWeb.ID.ToString()+"}" #Change schema XML on the lookup column $column.SchemaXml = $column.SchemaXml.Replace($column.LookupWebId.ToString(), $newLookupWebID) $column.SchemaXml = $column.SchemaXml.Replace($column.LookupList.ToString(), $newLookupListID) $column.Update() #Write confirmation to console and dispose of web object write-host "In Site" $web.Url "column " $column.Title "in Liste" $list.Title "is connected with" $lookupList.Title "from" $lookupWeb.Url $web.Dispose() $lookupWeb.Dispose() }
Fix Site Column with lookup
$webURL = "http://server/sites/XY" $listName = "MyList" $columnName = "MyColumn" $lookupListName = "Category" $lookupWebURL = "http://server/sites/X" RepairSiteLookupColumns -webURL $webURL -columnName $columnName -lookupListName $lookupListName -lookupWeb $lookupWebURL Function RepairSiteLookupColumns($webURL, $columnName, $lookupListName, $lookupWebURL) { #Get web, list and column objects $web = Get-SPWeb $webURL $lookupWeb = Get-SPWeb $lookupWebURL $column = $web.Fields[$columnName] $lookupList = $web.Lists[$lookupListName] $newLookupListID = "{"+$lookupList.ID.ToString()+"}" $newLookupWebID = $web.ID.ToString() $column.SchemaXml #Change schema XML on the lookup column $column.SchemaXml = $column.SchemaXml.Replace($column.LookupWebId.ToString(), $newLookupWebID) $column.SchemaXml = $column.SchemaXml.Replace($column.LookupList.ToString(), $newLookupListID) $column.Update() $column.SchemaXml #Write confirmation to console and dispose of web object write-host "In Site" $web.Url "column " $column.Title "in Liste" $list.Title "is connected with" $lookupList.Title "from" $lookupWeb.Url $web.Dispose() $lookupWeb.Dispose() }
Hope this helps you.
..:: I LIKE SHAREPOINT ::..