Feb 08 2018 01:34 AM
Targeting Office 365 / SharePoint Online, we are creating labels in the Office 365 compliance center, and would like to assign these as default labels in document libraries through code (e.g. CSOM/REST/Graph/PnP)
Is this possible, and are there any samples on this available?
I am looking at the Microsoft.SharePoint.Client.CompliancePolicy namespace, but the documentation is limited at best.
Feb 08 2018 04:46 AM
SolutionFeb 08 2018 05:00 AM
Hi Juan Carlos,
thanks hadn't seen that one - I will check it out and put a result here :)
/Brian
Feb 08 2018 11:32 AM
I can see that I can set the label on a document but I cannot see how to change the default label for a document library - the below will change the label of a document:
$list = $ctx.Web.GetList("/sites/somesite/somedoclib") $ctx.Load($list) $ctx.ExecuteQuery() $item = $list.GetItemById(DocumentItemID) $ctx.Load($item) $ctx.ExecuteQuery() $item.SetComplianceTagWithNoHold("MyLabel") $item.Update() $list.Update() $ctx.ExecuteQuery()
I will consider to add an ItemAdded remote event receiver and set the label when an item is added to the library (allowing the end user to change it if required) - but thanks for the pointer
Feb 08 2018 12:47 PM
What about using Flow or Webhooks instead of a Remote Event Receiver?
Feb 08 2018 12:50 PM
I will consider webhooks as well, but as this will be a large number of site collections and document libraries (read: all new team sites created), then a MS Flow dedicated to each wouldn't be feasible
But keep the ideas coming :)
Feb 08 2018 12:52 PM
Feb 08 2018 02:56 PM
Yes - that is what I'm considering with a webhook -> I'll poste a note when it's done :)
Apr 20 2018 04:30 AM
This was requested on UserVoice and it looks like this was included in the March 2018 SharePoint Online CSOM update. Mikael is very active in PnP, so hopefully we'll see it added there soon too....
Apr 20 2018 05:17 AM
Perfect - thanks, hadn't seen that uservoice entry :)
/Brian
Feb 08 2018 04:46 AM
Solution