public static void StartWorkflow(SPListItem listItem, string workflowName, SPWorkflowRunOptions runOption) { try { SPWorkflowManager manager = listItem.Web.Site.WorkflowManager; SPWorkflowAssociationCollection objWorkflowAssociationCollection = listItem.ParentList.WorkflowAssociations; Debug.WriteLine("WF.Count=" + objWorkflowAssociationCollection.Count.ToString()); foreach (SPWorkflowAssociation objWorkflowAssociation in objWorkflowAssociationCollection) { Debug.WriteLine("WF.InternalName=" + objWorkflowAssociation.InternalName); Debug.WriteLine("WF.Id=" + objWorkflowAssociation.Id.ToString()); if (String.Compare(objWorkflowAssociation.Name, workflowName, true) == 0) { Debug.WriteLine("WF.Selected"); try { SPWorkflowCollection wfc = manager.GetItemActiveWorkflows(listItem); bool isActive = false; foreach (SPWorkflow wf in wfc) { Debug.WriteLine("WF.InternalName=" + wf.ItemName); // wf.IsCompleted nie używać - blokuje kolejne uruchomienie procesu jeżęli status jest "Ukończono" if (wf.IsLocked && objWorkflowAssociation.Id.Equals(wf.AssociationId)) { isActive = true; Debug.WriteLine("WF.IsLocked=" + wf.IsLocked.ToString()); Debug.WriteLine("WF.AssociationId=" + wf.AssociationId.ToString()); break; } } if (!isActive) { SPWorkflow spw = manager.StartWorkflow(listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, runOption); Debug.WriteLine("Workflow: " + workflowName + " Internal State: " + spw.InternalState); //The above line will start the workflow... } else { Debug.WriteLine("WF aktualnie uruchomiony - kolejna aktywacja procesu przerwana"); //ElasticEmail.EmailGenerator.SendMail("wf aktualnie uruchomiony" + listItem.ID.ToString(), string.Empty); } } catch (Exception) { } break; } } } catch (Exception) { } }
public static void StartSiteWorkflow(SPSite site, string workflowName, SPWorkflowRunOptions runOption, string initiationData) { using (SPWeb web = site.OpenWeb()) // get the web { //find workflow to start var assoc = web.WorkflowAssociations.GetAssociationByName(workflowName, CultureInfo.InvariantCulture); //this is the call to start the workflow var result = site.WorkflowManager.StartWorkflow(null, assoc, initiationData, runOption); } }
public static void StartSiteWorkflow(SPSite site, string workflowName, SPWorkflowRunOptions runOption) { StartSiteWorkflow(site, workflowName, runOption, string.Empty); }