Fix: Document Sets Shared Column not inheriting metadata

 

I am writing this blog to address the issue with the Document Set items not inheriting the metadata value defined for the Document Set.

Problem:

You have created a Document Set in a library, you have set the metadata for the Document Set and you add new files to the Document Set. You expect that the metadata set for Document Set needs to be inherited by the Child Items, but is not happening.

First thing, you need to check if you have configured Shared Columns properly for the Document Set.

Not sure, how to configure Document Set or How to propagate the metadata automatically to the items in the Document Set?

Well, for that check out the link - Create and configure a new Document Set content type

Once you have verified that you have done the steps correctly as mentioned in the above article, we can move to the next step.

Cause:

There could be numerous cause why it may not work. The most common being missing or corrupted Document Set Event Receivers.

In this blog we are going to address how to fix the missing or corrupt Event  Receivers for the library that are responsible for setting the metadata for the Child Items in the Document Set.

In total, there are 6 event receivers that are added to a library when you add the Document Set Content Type to the library.

I have created the script that will add or replace corrupted Event Receivers.

Set the values for the WebURL & Library name in the script below and run the script using Farm account on any of the servers and hopefully your Document Sets should have the metadata propagated.

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ea SilentlyContinue;
$webURL = "<Enter Web URL>";
$libraryName = "<Enter Library Name>";

#Set to true if you want to see some debug info
$debugInfo = $false;



############################################################
#               Do not change below code                   #
############################################################




$web = Get-Spweb $webURL;
$docsLib = $web.Lists[$libraryName];

if($debugInfo)
{
    $docsLib.Title;
    $docsLib.EventReceivers.Count;
    $evtrcvrs1 = $docsLib.EventReceivers | where{$_.Class -eq "Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver" -or $_.Class -eq "Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetEventReceiver" };
    $evtrcvrs1.Count;
}

$assembly = "Microsoft.Office.DocumentManagement, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";
$class = "Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver";
$class2 = "Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetEventReceiver";

$rcvr1 = $docsLib.EventReceivers.Add();

$rcvr1.Assembly = $assembly;
$rcvr1.Class = $class;
$rcvr1.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemAdding;
$rcvr1.Name = "DocumentSet ItemAdding";
$rcvr1.Synchronization = "Synchronous";
$rcvr1.Update();

$rcvr2 = $docsLib.EventReceivers.Add();

$rcvr2.Assembly = $assembly;
$rcvr2.Class = $class;
$rcvr2.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemAdding;
$rcvr2.Name = "DocSetItemsEventReceiver ItemAdding";
$rcvr2.Synchronization = "Synchronous";
$rcvr2.Update();

$rcvr3 = $docsLib.EventReceivers.Add();

$rcvr3.Assembly = $assembly;
$rcvr3.Class = $class;
$rcvr3.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemUpdating;
$rcvr3.Name = "DocumentSet ItemUpdating";
$rcvr3.Synchronization = "Synchronous";
$rcvr3.Update();

$rcvr4 = $docsLib.EventReceivers.Add();

$rcvr4.Assembly = $assembly;
$rcvr4.Class = $class;
$rcvr4.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemUpdating;
$rcvr4.Name = "DocSetItemsEventReceiver ItemUpdating";
$rcvr4.Synchronization = "Synchronous";
$rcvr4.Update();

$rcvr5 = $docsLib.EventReceivers.Add();

$rcvr5.Assembly = $assembly;
$rcvr5.Class = $class;
$rcvr5.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemAdded;
$rcvr5.Name = "DocumentSet ItemAdded";
$rcvr5.Synchronization = "Synchronous";
$rcvr5.Update();

$rcvr6 = $docsLib.EventReceivers.Add();

$rcvr6.Assembly = $assembly;
$rcvr6.Class = $class2;
$rcvr6.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemUpdated;
$rcvr6.Name = "DocumentSet ItemUpdated";
$rcvr6.Synchronization = "Synchronous";
$rcvr6.Update();

$docsLib.Update();