다음을 통해 공유


How to resume SharePoint Workflows Hosted in Workflow Manager

If you have SharePoint workflows suspended in Workflow Manager for whatever reason (it was executed an explicit “Suspended” activity, an unexpected exception within the workflow, etc), you can resume these suspended messages as described below:

Note:  To check the number of suspended workflow instances for a specific Workflow definition, as well as the reason of that, instance ID, and so on, you can check next article: https://blogs.msdn.com/b/feseca/archive/2014/10/07/gathering-infomation-about-workflows-executed-by-workflow-manager.aspx

Method 1 : Programatically by using SharePoint Server API (SharePoint Server needs to be installed)

using (Microsoft.SharePoint.SPSite spSite = new Microsoft.SharePoint.SPSite("<SharePoint Site Collection where the Workflow was Added>")){

using (Microsoft.SharePoint.SPWeb spWeb = spSite.OpenWeb()){

var spWorflowManager = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(spWeb);

                  var spWorkflowInstaceSerice = spWorflowManager.GetWorkflowInstanceService();

                   var instance = spWorkflowInstaceSerice.GetInstance(newGuid("<Workflow Instance ID>"));

                   spWorkflowInstaceSerice.ResumeWorkflow(instance);

          }

}

Note: You neeed to add the following references:

    • Microsoft.SharePoint: \Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.dll
    • Microsoft.SharePoint.WorkflowServicesBase: \Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.WorkflowServicesBase\v4.0_15.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.WorkflowServicesBase.dll

 

Method 2: Programatically by using SharePoint Client API (SharePoint Client needs to be installed)

Microsoft.SharePoint.Client.ClientContext spClientContext = new Microsoft.SharePoint.Client.ClientContext("<SharePoint Site Collection where the Workflow was Added>");

NetworkCredential spCredential = newNetworkCredential (@"<SP user>", "<SP Password>");

spClientContext.Credentials = spCredential;

Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager spWorkflowServicesManager = new Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager(spClientContext, spClientContext.Web);

Microsoft.SharePoint.Client.WorkflowServices.WorkflowInstance spWorkflownInstance = spWorkflowServicesManager.GetWorkflowInstanceService().GetInstance(newGuid ("<Workflow Instance ID>"));

spWorkflowServicesManager.GetWorkflowInstanceService().ResumeWorkflow(spWorkflownInstance);

spClientContext.ExecuteQuery();

Note: You neeed to add the following references:

    • Microsoft.SharePoint.Client: \Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll
    • Microsoft.SharePoint.Client.Runtime: \Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll
    • Microsoft.SharePoint.Client.WorkflowServices: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll

 

It is important to notice that you should have at least SharePoint 2013 SP1 installed on your system, otherwise you might get below error while trying to execute ResumeWorkflow method:

Microsoft.SharePoint.Client.ServerException was unhandled
HResult=-2146233088
Message=Method "ResumeWorkflow" does not exist.
Source=Microsoft.SharePoint.Client.Runtime
ServerErrorCode=-1
ServerErrorTraceCorrelationId=3ec4c19c-80f0-d0f5-0000-0a5c1da41f56
ServerErrorTypeName=Microsoft.SharePoint.Client.InvalidClientQueryException
ServerStackTrace=""
StackTrace:
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at ConsoleApplication1.Program.Main(String[] args) in c:\ResumeSPWorkflows\GetSuspendedWorkflows\ConsoleApplication1\Program.cs
...

 

Hope you find it interesting.

Comments

  • Anonymous
    October 15, 2014
    Hi, I have SP1 installed and when I run your code I don't see any errors. But still the workflow internal status is not changing from "Suspended". Do you have any suggestions. Thank you.

  • Anonymous
    October 16, 2014
    Hi SK, If you don’t get error while resuming the workflow instance, it looks like the Workflow is suspended again once you have resumed it, perhaps because you have an exception happening at that point. Please, check check “WorkflowStatusDetails” (see blogs.msdn.com/.../gathering-infomation-about-workflows-executed-by-workflow-manager.aspx) to try to figure out what the exception is. Thanks, Felipe.