-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Refactor the Set-PnPListItem commandlet to use the 'SetComplianceTagOnBulkItems' endpoint for applying retention labels #3054
Comments
Hi @martinlingstuyl , just came across this page: https://learn.microsoft.com/en-us/sharepoint/dev/apis/csom-methods-for-applying-retention-labels Looks like it is available via CSOM now, but was not able to find a way , any idea about it ? |
Ah nice @gautamdsheth!! Totally missed that. It must have been right after I worked with it extensively. On what entity did you try it? I am currently on holidays. Will try it right after! Have you tried with the CompliancePolicy namespace? var policyStore = new SPPolicyStore(clientContext, web); |
Found it, @gautamdsheth: using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.CompliancePolicy;
//...
var result = SPPolicyStoreProxy.SetComplianceTagOnBulkItems(clientContext, new[] { 1,2,3 }, "https://contoso.sharepoint.com/sites/sales/Lists/TestList", "Some Label");
clientContext.ExecuteQueryRetry(); |
Feature #3054: improving compliance tag code in list item
@martinlingstuyl - have merged the refactored code. Works fine at my end, will be available in tomorrow's nightly as well as next major version. Let me know if you run into any issues :) |
Very nice @gautamdsheth!! 💖 |
@gautamdsheth , is there a way to do bulk date on all items in the library without specifying the item IDs? Thanks! |
Bulk update the retention labels of an entire library, is that what you mean @Lonewalker25? There is not, unless you would use default labels. Checkout my blog post on if you want to know more, there's also a section on default labels. https://www.blimped.nl/managing-and-applying-purview-retention-labels-using-code/ However, be advised: using default labels may have license implications. |
@martinlingstuyl I do not know about the license implications but I'm sure I will once I run into it. I read the blog again and I think this should be the section you referred to
I use Power Automate to run this. I understand applying tags needs time. However, I am finding that this action is more of a hit-or-miss. I have a few test libraries in a site, I have witnessed this so far:
|
Hi @Lonewalker25, In your answer you're referring to As far as I can see you're using it in the correct way. I haven't used the method extensively myself, but as far as I know I never ran into what your describing. The default label should be applied and synced. However, these are of course internal microsoft processes that we have no influence or control over. It might just be that some issues are holding them back. I fear you'd need to contact Microsoft Support for that. it may be they can identity the issue and fix it on their side. If you don't have the time to wait for Microsoft you could of course also automate it yourself using Default labels are really only the good solution if you want to apply a retention label on the entire container, so that (while people are still working in a library) all new items will receive the retention label as well. Another scenario would be that all the files in a library need to be archived and people will no longer work there. In that case I think I'd not use Default labels, but just automate it myself. |
The
Set-PnPListItem
commandlet currently uses theSetComplianceTag
endpoint for applying Retention Labels.However, this method will be deprecated in the near future. This is because of a concern on the boolean parameters that can be used with the endpoints. (See my blog for more information.
We should refactor this command to use the newer
SetComplianceTagOnBulkItems
endpoint. This endpoint does not have the same problems.Implementation
This newer endpoint can be used through CSOM or the REST API. The endpoint can be called as follows:
or using CSOM:
The endpoint returns a 200 response with an "odata.null": true. If a list item cannot be found, it will be returned. The endpoint will also throw an error if the label cannot be found.
An important thing to note is that you'll need the absolute URL of the list, which means we might need to execute an HTTP request to get at it.
The text was updated successfully, but these errors were encountered: