On my SharePoint Online site, I have created a SharePoint 2010 Site Workflow through SharePoint Designer.
Now, I want to create an instance and start that workflow through the CSOM Workflow API.
When I first publish the Workflow, everything works beautifully and the Workflow is indeed started (and completes successfully).
The problem occurs when I want to create another instance of the same workflow. Every time I try to run my code the second time, I get the same ClientResult<Guid>
back as the first time and the new instance is not started.
I am using the 16.0.0.0 version of Microsoft.SharePoint.Client.dll
and Microsoft.SharePoint.Client.WorkflowServices.dll
Here is my code:
using (ClientContext clientContext = new ClientContext("https://mytenant.sharepoint.com/sites/test"))
{
SecureString passWord = new SecureString();
foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);
Web web = clientContext.Web;
WorkflowAssociationCollection wfAssociations = web.WorkflowAssociations;
WorkflowAssociation wfAssociation = wfAssociations.GetByName("SP2010SiteWF");
clientContext.Load(wfAssociation);
clientContext.ExecuteQuery();
WorkflowServicesManager manager = new WorkflowServicesManager(clientContext, web);
InteropService workflowInteropService = manager.GetWorkflowInteropService();
ClientResult<Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, wfAssociation.Id, wfAssociation.ListId, new Guid(), null);
clientContext.ExecuteQuery();
}
The problem occurs with List Workflows too. Not only Site Workflows.