当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 修复查找字段

作者:精品下载站 日期:2024-12-14 15:31:20 浏览:14 分类:玩电脑

SharePoint Online:使用 PowerShell 修复查找字段


问题:重新创建父查找列表时,列表中的 SharePoint Online 查找列被破坏!

根本原因:

SharePoint Online 列表查找列通过“List”(父列表的 GUID)和“ShowField”属性与其父查找列表列连接。重新创建父查找列表时,会重新生成其 GUID,并且父查找列表和子查找列表之间的连接性会被破坏,并且查找字段值会变为空!

[玩转系统] SharePoint Online:使用 PowerShell 修复查找字段

如何修复 SharePoint Online 中损坏的查找列?

如果您遇到上述情况,并且查找列因空值而损坏,则必须将查找列与其父列表重新链接。使用此 PowerShell 脚本修复 SharePoint Online 列表中的查找列。


#Parameters
$SiteURL = "https://Crescent.sharepoint.com/sites/pmo"
$ParentListName = "Projects"
$ChildListName = "ProjectMilestones"
#Field display names - Case sensitive!
$ParentFieldTitle = "Title"
$ChildFieldTitle = "Project"

#Connect to SharePoint Online
Connect-PnPOnline $SiteURL -Credentials (Get-Credential)

#Get Parent List & Child field
$ParentList = Get-PnPList -Identity $ParentListName
$ChildField = Get-PnPField -List $ChildListName -Identity $ChildFieldTitle

#Get the Field Schema XML
[Xml]$Schema = $ChildField.SchemaXml

#Update Field Schema with New Parent List and Field
$Schema.Field.Attributes["List"].'#text' = "{$($ParentList.Id.Guid)}"
$Schema.field.Attributes["ShowField"].'#text' = $ParentFieldTitle
$ChildField.SchemaXml = $Schema.OuterXml
$ChildField.UpdateAndPushChanges($true)
Invoke-PnPQuery

另外,请记住,我们将父查找列表保存为包含内容的列表模板,并从中创建了一个新列表,以便关联的行值保持不变!因为子查找列表的查找字段的每一行中的Field值将指向父查找列表中的行ID。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯