SharePoint支持将列表保存成列表模板,但当列表包含Lookup字段时,通过模板创建的列表会丢失Lookup字段的信息。
通过PowerShell,可以修改Lookup字段的xml内容。
1 Function Fix-LookupColumn ($webURL, $listName, $columnName, $lookupListName) 2 { 3 #Get web, list and column objects 4 $web = Get-SPWeb $webURL 5 $list = $web.Lists[$listName] 6 $column = $list.Fields.GetField($columnName) 7 $lookupList = $web.Lists[$lookupListName] 8 9 #Change schema XML on the lookup column 10 $column.SchemaXml = $column.SchemaXml.Replace($column.LookupWebId.ToString(), $web.ID.ToString()) 11 $column.SchemaXml = $column.SchemaXml.Replace($column.LookupList.ToString(), $lookupList.ID.ToString()) 12 $column.Update() 13 14 #Write confirmation to console and dispose of web object 15 write-host "Column" $column.Title "in list" $list.Title "updated to lookup list" $lookupList.Title "in site" $web.Url 16 $web.Dispose() 17 }
使用
Fix-LookupColumn -webURL http://server/web -listName "Idea Management" -columnName "IdeaPriority" -lookupListName "Priorities"