Update shared fields in a document set

7 Oct

To update shared fields in a document set using Office 365 Dev PnP PowerShell Cmdlets the following cmdlet can be used:

Set-SPODocumentSetField -Field "fieldname" -DocumentSet "documentsetname" -SetSharedField

This cmdlet sets the field from the available content types to the document set.
from the available content types
Besides that the functionality isn’t available in the UI, the functionality seems a little bit odd, especially when multiple content types are available in the document set. Why share fields at the level of ‘available content types’?
It seems more plausible to me to make a shared field available at document set level like the UI suggests and explains:

Select which column values for the Document Set should be automatically synchronized to all documents contained in the set.

Enough of the confusion…
In my case I had a field at document set level which I wanted to add to the shared fields collection.

When trying to use the Office 365 Dev PnP PowerShell cmdlet at that level a warning was shown:

Warning: Field not present in document set allowed content types

Luckily PowerShell and CSOM can be used to accomplish this:

$fieldName = "MyText" # field name at document set level
$ctName = "MyDocSet" # document set name

$ctx = Get-SPOContext
$docset = Get-SPODocumentSetTemplate -Identity $ctName

$field = $ctx.Web.Fields.GetByInternalNameOrTitle($fieldName)
$ctx.Load($field)

if($field)
{
 $docset.SharedFields.Add($field)
 $docset.Update($true)
 Execute-SPOQuery
}

DocSet_MyDocSet

3 Replies to “Update shared fields in a document set

  1. Hi Nes,

    Since 2016 the PnP PowerShell cmdlets were renamed from ‘-SPO’ to ‘-PnP’.
    You can use Get-PnPDocumentSetTemplate.

    Regards, Anita

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.