Skip to main content

Posts

Showing posts with the label object model

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 2 - workflow statistics, workflow tasks, workflow history

The task 1. Get links to workflow statistics. 2. Get workflow tasks programmatically. 3. Get workflow history programmatically Solution 1. Links to workflow statistics: foreach (SPWorkflow wf in list_item.Workflows) { string sLink = string.Format("{0}/_layouts/WrkStat.aspx?List={1}&WorkflowInstanceID={2}", web.Url, wf.ListId, wf.InstanceId) } web.Url above is the Url property of SPWeb instance. 2. Workflow tasks: foreach (SPWorkflowTask wt in wf.Tasks) { // get any information you like about the wt object, i.e. in this scenario we will output link to the task string sLink = string.Format("{0}/Lists/{1}/DispForm.aspx?ID={2}", web.Url, SPEncode.UrlEncode(wt.ParentList.Title), wt["ID"]) ... } 3. Workflow history: Class SPWorkflow has a member HistoryList which represents history list for the workflow. Let's assume that we are using the SPWorkflow object - wf - from above. 3.1. First we have to make a query to extract history list item ...

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