Monday, December 26, 2011

Expiration Date not getting updated when policy updated in Sharepoint

If the expiration date is no getting updated when policy gets updated then you need to run the Information management policy job & Expiration policy job.


Policy and Retention Execution
Policy and Retention Execution Logic includes two timer jobs
1.    Information Management Policy : Loops through all the lists in the site collections in a Web application and collects policy and usage data.
2.    Expiration Policy : Enumerates list items and looks for those with an expiration date that has already occurred. For those items, runs disposition processing. Disposition processing most often results in deleting items, but it can perform other actions, such as processing disposition workflows.
By default, these timer jobs are set to run weekly. Any stages that are due are processed at the time of expiration of the Expiration Policy timer job. However, if the policy schedule was just updated and the Information Management Policy timer job was not run to update the items, then they will not be processed by the Expiration policy timer job. To prevent this from happening, SharePoint Server 2010 runs the Information Policy timer job before the Expiration policy timer job by default.
To update the Expiration date in the document library, you can run the “Information Management Policy” timer job. Once you have done that the expiration date should be updated.
To run the job you can do it through central administration or use the below sample code to do it.
UI
Go to Central administration -> monitoring -> Review Job definition. Check for “Information Management Policy” under the corresponding webapplication and click ‘run now’.
SAMPLE CODE
using (SPSite site = new SPSite("http://YourSitecollectionURL"))
            {
                List<string> jobNamesToRun = new List<string>()
                {
                          "Information management policy",
                           "Expiration policy"
                };

                var jobsToRun = site.WebApplication.JobDefinitions.Where(job => jobNamesToRun.Contains(job.DisplayName));
                foreach (var job in jobsToRun)
                {
                    Console.WriteLine("Running job " + job.DisplayName);
                    job.RunNow();
                }
            }
            Console.WriteLine("Please click Enter to exit..");
            Console.ReadLine();

 

No comments:

Post a Comment