Testing the history of Autocleanup workflows

I ran into a rather peculiar problem. We have an OOTB approval workflow that logs the entire workflow history in the workflow history list. This list is cleared every 60 days. To lengthen this time period for which the workflow history is kept, I googled around and found that I ran this code:

using (SPSite wfSite = new SPSite (siteUrl)) {

using (SPWeb wfWeb = wfSite.OpenWeb(webName))

{

     SPList wfList = wfWeb.Lists[listName];

     SPWorkflowAssociation _wfAssociation = null;

     foreach (SPWorkflowAssociation a in wfList.WorkflowAssociations)

     {

         if("approval 1" == wfAssociationName.ToLowerInvariant())

         {

             a.AutoCleanupDays = newCleanupDays;

             _wfAssociation = a;

             assoCounter++;

         }

         else

         {

             _wfAssociation = a;

         }

     }

     wfList.UpdateWorkflowAssociation(_wfAssociation);

}

      

}

The code works great in the sense that it doesn't throw any exceptions. So far, so good. But now my problem is I need to check if my code is working. So I set the newCleanupDays variable to 0. But I see that new worker processes are still being registered in the list of worker process history. I can set the variable to 1, but that would mean waiting a whole day to see if the code works.

Is there a way to test my script so that I can set the autocleanup days to 1 and I don't have to wait all day to see if my code is working? Can I "trick" the system into thinking that 1 day has passed? I tried changing the system time and restarting the server and that's it, but it didn't work for me.

+1


source to share


1 answer


Changing the system time should work, but you will need to start a timer job that will initiate workflows. Do not restart the server after changing the time.



One caveat is that SharePoint really really doesn't like time travel. All documents created in the "future" will have problems. So be sure to test the new website that you can remove when you return to "now".

+2


source







All Articles