Skip to main content

Posts

Showing posts with the label workflow instance

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 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) {...