SharePoint支持将列表保存成列表模板,但当列表包含Lookup字段时,通过模板创建的列表会丢失Lookup字段的信息。
通过PowerShell,可以修改Lookup字段的xml内容。
Function Fix-LookupColumn ($webURL, $listName, $columnName, $lookupListName)
{
#Get web, list and column objects
$web = Get-SPWeb $webURL
$list = $web.Lists[$listName]
$column = $list.Fields.GetField($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())
$column.Update() #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
$web.Dispose()
}
使用
Fix-LookupColumn -webURL http://server/web -listName "Idea Management" -columnName "IdeaPriority" -lookupListName "Priorities"