【问题标题】:How to update a managed metadata file property in SharePoint Online如何在 SharePoint Online 中更新托管元数据文件属性
【发布时间】:2018-06-15 22:10:26
【问题描述】:

我正在尝试在位于文档库中的文件夹中的文件的托管元数据列上设置属性值。我可以为其他元数据设置值,因为它们是文本字段。我相信我必须将其转换为另一种类型才能设置值。我尝试了各种我发现的方法,但似乎没有任何效果。 “Doc Type”是有问题的托管元数据列。

$files = Get-PnPFolderItem -FolderSiteRelativeUrl $folderRelativeUrl -ItemType File 

foreach($file in $files)
{
    write-output $file.Name
    $file.Properties['Business Unit'] = $Global:BusinessUnit
    $file.Properties['Customer Name'] = $Global:CustomerName
    $file.Properties['Customer No'] = $Global:CustomerNumber
    #$file.Properties['Doc Type'] = $Global:DocType
    $file.Properties['Doc Type'] = $term.Name
    $file.Properties['Job Name'] = $Global:JobName
    $file.Properties['Job Number'] = $Global:JobNumber
    $file.Properties['Opportunity Name'] = $Global:OpportunityName
    $file.Properties['Opportunity No'] = $Global:OpportunityNumber
    $file.Properties['Quote Name'] = $Global:QuoteName
    $file.Properties['Quote ID'] = $Global:QuoteNumber
    $file.Properties['System'] = $Global:System
    $file.Update()

我正在使用此命令从术语库中获取术语

$term = Get-PnpTerm -TermGroup "Document Types" -TermSet Document -Identity $Folder -ErrorAction Ignore

$Folder 是我在术语库中查找的名称,例如:“Quote”。

【问题讨论】:

    标签: powershell metadata taxonomy sharepoint-online


    【解决方案1】:

    您可以考虑以下选项来设置分类值:

    注意:假设Doc Type 是一个单值分类字段

    选项 1

    通过来自 CSOM API 的 Taxonomy,如下所示:

    $files = Get-PnPFolderItem -FolderSiteRelativeUrl $folderRelativeUrl -ItemType File 
    
    $term = Get-PnpTerm -TermGroup $termGroup -TermSet $termSet -Identity $termId 
    
    #1. get taxonomy specific field
    $ctx = $files.Context
    $field = $files.ListItemAllFields.ParentList.Fields.GetByInternalNameOrTitle($fieldName) 
    $ctx.Load($field)
    $ctx.ExecuteQuery()
    $taxField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($ctx, $field)
    
    foreach($file in $files)
    {
        write-output $file.Name
    
        $taxField.SetFieldValueByTerm($file.ListItemAllFields,$term,1033) #2.update taxonomy field value
        $file.ListItemAllFields['Job Name'] = $Global:JobName
        $file.ListItemAllFields.Update()
        #$file.Update()    
    }
    

    选项 2

    通过 PnP-PowerShell SetPnPTaxonomyFieldValue cmdlet:

    foreach($file in $files)
    {
        write-output $file.Name
        Set-PnPTaxonomyFieldValue -ListItem $file.ListItemAllFields -InternalFieldName 'DocType' -TermId $term.Id        
    }
    

    【讨论】:

    • 我应该提到这是一个单一的价值。选项 2 工作正常。感谢您的回复。
    猜你喜欢
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 2021-10-13
    • 2021-11-04
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多