3

Currently, I have a workflow [WF1] that would check if the item has been submitted or saved. If it has been submitted, then the workflow would start another workflow [WF2] for the approval process. Everything works smoothly for this.

However, if a user edits an item and resubmits it while WF1 or WF2 is currently in progress, WF1 or WF2 would encounter an error since you cannot start a workflow that's already running.

So what I would want is when a user does this, the running workflows would be stopped or canceled then I would start WF1 again. Is there any way that I could do this through another workflow?

2 Answers 2

2

I don't think you can have one workflow clean up unfinished tasks either as a SharePoint Designer workflow cannot work in a state machine.

You could put a ton of logic into it, effectively a try-catch for each step, but you might go insane doing that

Please check the answer at below article.

Can you use a workflow to terminate another workflow

10
  • Do you have any approach to accomplish this? Right now I've tried to create another workflow that would set another status if WF1 or WF2 is currently running. However, it looks like I would still need to stop these workflows from within before I could start it again
    – sueshi
    Jun 29, 2016 at 9:16
  • I understand that you are running those workflows on both options 1.) on item adding 2.)on item updating. So If you want to run them only on item added than you should not run the wokflow on updating item.
    – Hardik
    Jun 29, 2016 at 9:20
  • You must tick only one check box called "Start workflow when an item is created"..Please see this image for reference..dhhmzgirqh63s.cloudfront.net/21920.gif
    – Hardik
    Jun 29, 2016 at 9:22
  • Please correct me if I am wrong as i am not aware about your scenario.
    – Hardik
    Jun 29, 2016 at 9:22
  • 1
    It is not possible through SharePoint designer to stop workflow using another workflow..
    – Hardik
    Jun 29, 2016 at 11:45
0

As other's have mentioned, this couldn't be done from another workflow. However you could stop that active workflow using splistitem itemupdated event receiver.

        SPSecurity.RunWithElevatedPrivileges(delegate ()
        {
            using (SPSite site = new SPSite(properties.SiteId))
            {
                using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
                {
                    SPWorkflowManager manager = site.WorkflowManager;
                    SPListItem item = web.Lists[properties.ListTitle].GetItemById(properties.ListItemId);
                    foreach (SPWorkflow workflow in manager.GetItemActiveWorkflows(item))
                    {
                        foreach (SPWorkflowTask t in workflow.Tasks)
                        {
                            t["Status"] = "Canceled"; t.Update();
                        }
                        SPWorkflowManager.CancelWorkflow(workflow);
                    }
                }
            }
        });

ref: https://social.msdn.microsoft.com/Forums/office/en-US/ef2be95b-f04f-429c-8895-8f1db308ef63/how-to-terminate-sharepoint-list-workflow-programmatically-in-an-event-receiver?forum=sharepointdevelopmentprevious

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.