0

Our custom code starts the workflow using classes in the Microsoft.SharePoint.WorkflowServices namespace but we can't seem to find a method to end the workflow.

Your help and time is greatly appreciated. Thank you. :)

3 Answers 3

2

I wouldn't use the server side OM (what you reference in your post), use the CSOM implementation as it's going to work both in an on-prem & Office 365 option. What you need to do is get a reference to the specific instance you want to work with.

You first need a reference to the instance service and then pass in the ID of the list & list item to see all instances, like this:

// connect to the workflow services via a CSOM client context
var clientContext = new ClientContext(siteCollectionUrl);
var workflowServicesManager = new WorkflowServicesManager(clientContext, clientContext.Web);

// connect to the instance service
var workflowInstanceService = workflowServicesManager.GetWorkflowInstanceService();

// get all instances
var workflowInstances = workflowInstanceService.EnumerateInstancesForListItem(listId, listItemId);
clientContext.Load(workflowInstances);
clientContext.ExecuteQuery();

From there, you can enumerate each of them and find the one you want to suspend or terminate:

foreach (var instance in workflowInstances)
{
  // is this what we are looking for?
  // ...

  // if so, suspend it
  workflowInstanceService.SuspendWorkflow(instance);

  // or you can terminate it
  workflowInstanceService.TerminateWorkflow(instance);
}
1
  • Hi Andrew, sorry I missed this reply previously. Thank you very much!!
    – Celbester
    Commented Oct 30, 2013 at 13:28
0

I can remember that I did it some time before (where were possibilities not only to cancel workflow, but also to suspend and resume), but I could not find my solution for a while. If it is not so urgent, I can try to find some time tomorrow to do that again.

2
  • Hi Mikhail, yes please. Or actually even just online references (if any) will be of big help already. Batiste at social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/… has suggested looking at the WorkflowInstanceService class.
    – Celbester
    Commented May 29, 2013 at 13:45
  • Hi Celbester. I had a lot of work and have completely forgotten that wanted to help you. Sorry for that! Is the question still actual?
    – MikhailSP
    Commented Jun 13, 2013 at 13:39
-1

A second way is to use the workflow client via this blog post:

http://blogs.architectingconnectedsystems.com/blogs/cjg/archive/2013/12/03/HowTo_3A00_-Terminate-all-SharePoint-2013-workflows.aspx

1
  • 1
    Can you please extend your answer with more details, if the link breaks your answer will not be very useful right now :) Commented Dec 4, 2013 at 18:17

Your Answer

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

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