Skip to main content
< All Articles

How to auto-apply retention labels to documents in SharePoint Online

Posted on August 19, 2024
SharePoint

In most of my previous articles about Retention labels and policies, the assumption was that users would ultimately decide on the retention of a specific document based on some of its characteristics (document type, purpose, etc.). While we have some means to apply retention to the whole document library or folder and its contents, there is also a way to auto-apply retention labels based on metadata already applied to the document. So, in this article, I would like to explain how you can take advantage of existing metadata tags and apply retention and records labels to documents tagged with specific values.

Use Case

  1. I have defined a Content Type within the Content Type Gallery (in SharePoint Admin Center) called Company Invoice. The Content Type contains a few invoice-related metadata columns (Client, Invoice Amount, Invoice Due Date, etc.). By the way, if you want to learn more about Content Type Gallery, check out this article.Autoapplylabelsretentionpurview1
  2. I then published this content type to all the sites.Autoapplylabelsretentionpurview2
  3. The End Users added the global content type to their libraries.Autoapplylabelsretentionpurview3auto-apply retention labels
  4. And tagged some of the documents with it and the corresponding metadata. In the screenshot below, you can see one such library that contains various project documents, some of which are tagged against Content Type = Invoice.Autoapplylabelsretentionpurview5

I now would like to automatically apply a retention label that would keep all the Invoices for 7 years from the time they were created.

How to auto-apply retention labels to documents in SharePoint Online

  1. The first step in the process is, of course, to create a retention label we are going to apply later in this article automatically. I already documented how to do this in an earlier post – check it out.auto-apply retention labels
  2. In my case, I already created a Financial Document label that retains a document for 7 years and makes it a record for that period of time.
  3. Next, we need to auto-apply the label via policy. To do so, navigate to Microsoft Purview (Microsoft 365 App Launcher > Compliance).Autoapplylabelsretentionpurview6
  4. Under Solutions > Data lifecycle management, click on Microsoft 365.Autoapplylabelsretentionpurview7
  5. Under Label policies tab, click Auto-apply a label.auto-apply retention labels
  6. Give your policy a name, and click Next.Autoapplylabelsretentionpurview9
  7. Now, there are different ways/methods to auto-apply labels, for now, we will Apply label to content that contains specific words or phrases, or properties. Click Next.auto-apply retention labels
  8. On the next screen, you will be prompted to enter the word, phrase, or property. In our case, we want to apply the label to all the Content Types = Invoice, so Managed Properties/Keyword Query Language (KQL) to the rescue! In my case, I am typing the following query using managed properties/KQL: SPContentType:”Company Invoice”. Essentially, the query will find all the documents tagged as Content Type = Invoice. Click Next.auto-apply retention labels
  9. On the next screen, you can choose Admin Units (optional and not required for most organizations). To learn more about Admin Units, click here. Click Next.Autoapplylabelsretentionpurview12
  10. Choose whether you want to apply either an Adaptive or Static scope. To learn more about adaptive scope types, click here. I proceed with Static.auto-apply retention labels
  11. Choose the site(s) you want to apply the policy to. Click Next.auto-apply retention labels
  12. Choose the label that you created in Step 1.auto-apply retention labels
  13. Choose the label. Click Add.Autoapplylabelsretentionpurview16
  14. On the next screen, click Next.Autoapplylabelsretentionpurview17
  15. On the next screen, you have a choice to either test the policy or turn it on immediately. Choose Turn on policy and click Next.
    Autoapplylabelsretentionpurview18
  16. Review the settings on the final screen; if everything looks good, click Submit.Autoapplylabelsretentionpurview19
  17. You will then receive a confirmation message that the policy has been created.Autoapplylabelsretentionpurview20
  18. After several days, you will notice that the policy takes effect, and the documents identified in the query above will be tagged with proper retention labels.
    auto-apply retention labels

Important Notes:

  • It might take a week or so to auto-apply retention labels based on this method – so be patient.
  • In the Conditions/Query box above, you can type in any KQL queries and use Managed Properties such as RefinableString. For example: SPContentType:”Company Invoice” AND RefinableString25:Paid.
  • When you specify the query – you can’t use aliases for the managed properties – you have to type in the actual managed property name (i.e., RefinableString25)
  • Since the label is auto-applied via the query, you are not going to see it being available within the Document Information Panel. You will be able to clear (remove) the label, but you are not going to see it in the drop-down and re-apply manually.Autoapplylabelsretentionpurview22
  • The above method applies to both the regular retention labels and record labels.

About Me

I’m Greg Zelfond, a U.S. based SharePoint consultant, and I provide affordable out-of-the-box SharePoint consulting, training, and configuration assistance to small and medium-sized businesses all over the world.

Need help?