Force execution of expiration policies in MOSS

When you develop actions (or workflows) that should be executed when an expiration policy occurs you need to test them, and that is problem in MOSS as the Expiration Policy job only is scheduled to run once a day. Probably you can't sit around waiting all day for the job to run so you will have to force it's execution.

My first though was that there ought to be some operation in STSADM.EXE that would support this. But I did not find any! If there are any operation for this please let me know!

I then reverted to building an application that will find the Expiration policy job and execute it. After looking through the classes and methods available this is the code I came up with:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics; 

using Microsoft.SharePoint.Administration;

namespace RunExpirationPolicy
{
class Program
{
static void Main(string[] args)
{
foreach (SPService srv in SPFarm.Local.Services)
{
foreach (SPJobDefinition job in srv.JobDefinitions)
{
string jobTitle = job.Title;

               if (jobTitle == "Expiration policy")
{
Trace.WriteLine("***************** Start of execution for expiration policy job");
job.Execute(Guid.Empty);
Trace.WriteLine("***************** End of execution for expiration policy job");
}
}
}
}
}
}

I think it's simple and quite obvious what it does. The only thing that is not obvious is why there is a Guid.Empty as parameter, it is there because it is required but only has meaning in a specific case which does not apply here (read more on MSDN).

As I use this for debugging my custom actions I have included Trace calls which log the start and end of the execution of the Expiration job. During my tests so far I have received all the traces made by my custom action within the Start and End traces, if this is always true I don't know but it works fine for me.

Comments

  • Anonymous
    June 04, 2007
    PingBack from http://www.virtual-generations.com/2007/06/05/sharepoint-link-love-06-05-2007/

  • Anonymous
    April 27, 2008
    The executes with no errors but the TimeLastRun for the job "Expiration policy" in Central Admin doesn't shows the latest one. I don't know whether the job executed successfully or not. Pls give more details regarding the same. Thanks.

  • Anonymous
    July 03, 2008
    Information Management Policies – Expiration The question is, when an information management expiration