Well, if you associate a workflow to any sharepoint list/ library & if the workflow instance is completed, then its association with its tasks and history list details will lasts for only 60 days. This is because we have a sharepoint out of the box "Workflow Auto clean up" timer job running daily for every webapplication.
If you want to change the default 60 days of clean up, then you are the right stop. The below sample will help you out to achieve the behaviour.
static void Main()
{
{
using( SPWeb web = site.OpenWeb())
{
SPWorkflowTemplateCollection collection = web.WorkflowTemplates;
SPList list = web.Lists["LIST_NAME"];//List name
SPWorkflowAssociation _asso = null;
foreach (SPWorkflowAssociation asso in list.WorkflowAssociations)
{
if (asso.Name == "WORKFLOW_NAME")//Workflow name
{
asso.AutoCleanupDays = 7;//clean up days
_asso = asso;
}
}
list.UpdateWorkflowAssociation(_asso);
}}
}
Happy Coding !!!!!
this turns it off? do you have to run this all the time?
ReplyDelete