A short and sweet post based on a customer inquiry.
A customer recently asked me this: “Is it possible to apply a retention label to content 20 days after last modified?”. Their use-case was they initially want to allow end-users to create/edit/delete documents without having any retention label applied. Only after a period of time has elapsed since the document was last modified should a retention label be applied.
[UPDATE January 2024] Do not use the technique I describe in this post. Released not long after this post was originally published, you can use a replacement label to accomplish the same thing and it’s a much easier configuration. Excerpt from Microsoft article:
- If you don’t need to initially retain content with the primary label: On the Define label settings page, select Enforce actions after a specific period, specify the retention period, and then select Change the label > Choose a replacement label.
- Link: Configuration paths for relabeling
I will leave my original post below. (Technically it will still work for this use-case, but I would use the built-in capability above instead now).
The answer is yes, with some constraints. It can be done using a Keyword Query Language (KQL) query in an auto-apply retention label policy.
The constraint is this… you can’t do a specific number of days or do date math in your KQL query; however, you can use any of the supported date keywords in the date condition, which in some cases, can get you fairly close. (link: Relevant date intervals supported by KQL)
Configuration steps:
- Define a retention label
- Map the crawled property, ows_Modified, to a RefinableDate managed property
- Initiate a re-index of the sites where you want the labels to be applied to ensure the RefinableDate managed property is updated in the search index for the content
- Verify the query.
- I verified the KQL query in 3 search tools before proceeding (Microsoft Search, Content Search, and the SharePoint Search Query tool). The reason I did this was to determine which managed property was the correct one to use in the auto-apply condition for a last modified date: LastModifiedTime, LastModifiedTimeForRetention, or my mapped RefinableDate managed property. I received consistent results across all 3 search tools above with the RefinableDate managed property rather than LastModifiedTime or LastModifiedTimeForRetention (even though LastModifiedTimeForRetention is mapped to crawled property ows_Modified as well). Ymmv.
- Using an auto-apply label policy, auto-apply the retention label to sites using the condition that best suits your needs. By using <“last month” in my query, content will have the label auto-applied when its last modified date is more than ~30 days ago. Below is the date condition in the auto-apply label policy (ensure you add any additional conditions to suit your retention needs):
After ~7 days…
All content matching the above condition (last modified more than ~30 days ago with a content type of ‘document’ had the retention label applied.)
Remember… once a retention label is applied to an item, it can’t be overwritten by another auto-apply label policy. It can; however, be manually updated.
Thanks for reading. Told you it was short and sweet. 🙂
-JCK
3 comments