Pages

Wednesday, April 9, 2008

SharePoint Workflow History Cleanup jobs ...

When I first saw this post - Huge MOSS workflow issue ... What is Microsoft thinking!!! - I was shocked. But fortunately the soup is not eaten as hot as it's cooked ...

There is indeed a timer job  (Check SharePoint Central Admin > Operations > Timer Job Definitions) which removes the link between the item on which a workflow has run and the entries in the workflow history list. This means that the info in a workflow history list will not be complete anymore after a certain period of time (default 60 days).

Luckily Robert Bogue gave some more background information in SPWorkflowAssociation.AutoCleanupdays as well as some workarounds:

  • Purging of this list is done using a SharePoint timer job - if you build your own custom workflows you can change the setting by modifying workflow.xml in the features folder like this

    <Elements>

        <Workflow>

          <MetaData>

              <AutoCleanupDays>99999</AutoCleanupDays>

          </MetaData>

       </Workflow>

    </Elements>

  • You can modify this setting using the SharePoint object model - as Robert's postings suggest take a look at the SPWorkflowAssociation.AutoCleanupdays property. Take a look at the next code sample
  • using (SPSite sitecollection = new SPSite("http://moss:99"))
    {
    using(SPWeb site = sitecollection.OpenWeb("/demo")){
    SPWorkflowAssociation _assoc = null;
    SPList list = site.Lists["Shared documents"];
    foreach (SPWorkflowAssociation assoc in list.WorkflowAssociations)
    {
    if (assoc.Name == "WFDemo")
    {
    _assoc = assoc;
    _assoc.AutoCleanupDays = 2;
    }
    }
    list.UpdateWorkflowAssociation(_assoc);
    list.Update();
    }
    }



 



0 comments:

Post a Comment