Skip to main content

Posts

Showing posts with the label workflow association

Mighty SharePoint Workflows - part 4 - Start/restart SharePoint workflow programmatically

Scenario We want to start or restart SharePoint workflow programmatically for the list item. Solution SPList list = ...; // initialise your list SPWorkflowAssociation workflowAssociation = null; workflowAssociation = list.WorkflowAssociations.GetAssociationByName("Mighty Workflow", System.Globalization.CultureInfo.CurrentCulture); if (workflowAssociation != null) { foreach (SPListItem item in list.Items) { foreach (SPWorkflow wf in item.Workflows) { if (wf.AssociationId == workflowAssociation.Id) { // if we want to restart - cancel the running one first if (!wf.IsCompleted) { try { SPWorkflowManager.CancelWorkflow(wf); } catch { } } // ...

Mighty SharePoint Workflows - part 3 - workflow history and audit solutions

I came across the limitation of the workflow history in SharePoint the other day. After 60 days the history is cleaned up. Technically it's the right way of doing things in SharePoint, because workflow history is a list and if we have more than 2000 records in the list we have performance issues. There are some blog posts about that issue. The main one: Huge MOSS Workflow Issue... What is Microsoft Thinking!!!! The other linked to the issue: SPWorkflowAssociation.AutoCleanupDays I worked with several clients on custom workflows for SharePoint and we created the separate audit database where all the SharePoint workflow activity information and list/library item information is stored. For guys who have already created workflows in SharePoint or use standard SharePoint workflows - like Approval etc. - and they are not sure what to do the solution is to develop or purchase a tool to migrate their workflow history to separate database on a regular basis. I can help with that...

Mighty SharePoint Workflows - part 1 - workflow association, workflow instance

The task Display SharePoint lists or libraries with active workflow associations. Display item that have running or completed workflow instances and workflow status for this item. In our scenario we have a document library with associated Disposition Approval workflow started on the document: Solution 1. Get Workflow Association data for the certain list or library. SPList list = ...; // Initialize your list instance here if (list.WorkflowAssociations.Count != 0) { foreach (SPWorkflowAssociation workflowAssociation in list.WorkflowAssociations) { Guid gId = workflowAssociation.Id; string sName = workflowAssociation.Name; ... // output the values you have got // in our scenario we add them to Hashtable object hashtable.Add(gId, sName); } } 2. Get workflow instance data for the certain list item or document. We can access workflow instance data from the Workflows property of SPListItem object: foreach (SPListItem item in list.Items) {...