MOSS Workflow History Association

Based on a lot of the blog sites, SharePoint 2007 (MOSS) has a timer job that will purge the workflow history association with the work item after 60 days. For most of the users, this is not a good thing because our their audit depends on it. I have read a few solutions that can work around this issue.

  1. Use a custom list for audit and do not depend on the workflow hisory. Based on Microsoft, workflow history is not intended for audit purposes. You should probably always create a separate audit log. You can write code to log your workflow history or events to a separate list. Try to use folder structure (i.e. year, month, workflow ID, etc...) so that you don't have more than 2000 items in a view/folder.
  2. Write code to change the default days from 60 to whatever your requirement is. There is a sample code that was posted on one of the comments in this post(http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/b15b27e2-3033-418b-9731-968273d7423e). I have copied and pasted here for your quick reference.




Code Snippet
/*
* Date: September 17, 2007
*
* Program Description:
* ====================

* This program is a workaround for Microsoft Office SharePoint Server 2007

* bug #19849, where the AutoCleanupDays is set to 60 by default and by design

* in MOSS installations. This program gives the customer the oppotunity to

* change this number.

* Workflow histories would not show after 60 days by default.

*/

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Workflow;



namespace ShowWFs

{

class Program

{

static string siteName;

static int newCleanupDays, assoCounter;

static string libraryName, wfAssoName;

static SPSite wfSite;

static SPWeb wfWeb;

static SPList wfList;

static void Main(string[] args)

{


try

{

switch (args.Length)

{

case 0: //no parameters entered by user

{

System.Console.WriteLine("Error: No arguments entered (site, library, workflow and days)");

showHelpUsage();

break;

}

case 4: //correct number of parameters

{

siteName = args[0];

libraryName = args[1];

wfAssoName = args[2];

newCleanupDays = Convert.ToInt32(args[3]);

assoCounter = 0;

wfSite = new SPSite(siteName);

wfWeb = wfSite.OpenWeb();

wfList = wfWeb.Lists[libraryName];

SPWorkflowAssociation _wfAssociation = null;

foreach (SPWorkflowAssociation a in wfList.WorkflowAssociations)

{

if (a.Name == wfAssoName)

{

a.AutoCleanupDays = newCleanupDays;

_wfAssociation = a;

assoCounter++;

}

else

{

_wfAssociation = a;

}

}

wfList.UpdateWorkflowAssociation(_wfAssociation);

System.Console.WriteLine("\n" + wfAssoName + ": " + assoCounter.ToString() + " workflow association(s) changed successfuly!\n");

break;


}

default: //default number of parameters

{

System.Console.WriteLine("Incorrect number of arguments entered (" + args.Length.ToString() + " arguments)");

showHelpUsage();

break;

}

}


}

catch (Exception e)

{

System.Console.WriteLine("An error has occurred. Details:\n" + e.ToString());

}

finally

{

if (wfSite != null)

wfSite.Dispose();

if (wfWeb != null)

wfWeb.Dispose();

System.Console.WriteLine("\nFinished setting AutoCleanupDays!");

}

}

static void showHelpUsage() //help screen

{

System.Console.WriteLine("\n\nMOSS Workflow Set AutoCleanup Usage:");

System.Console.WriteLine("====================================");

System.Console.WriteLine("ShowWFs siteURL library workflow days");

System.Console.WriteLine(" - siteURL (e.g. http://serverURL/site)");

System.Console.WriteLine(" - library (e.g. \"Shared Documents\")");

System.Console.WriteLine(" - workflow (e.g. \"Approval\")");

System.Console.WriteLine(" - days for auto clean up (e.g. 120)");

}

}

}


Comments

Popular posts from this blog

SharePoint 2013 - Working with Display Template for Content Search Web Part

How to Customize MOSS Site Manager (Site Content and Structure Page)

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365