1

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.

3
  • Do you want to start same workflow "SP2010SiteWF" to some other item or associate that workflow to some other list?
    – Aanchal
    Commented May 28, 2014 at 16:12
  • It's a site workflow and I want to start another instance on the web. Commented May 28, 2014 at 16:22
  • Check the solution, it might help you.
    – Aanchal
    Commented May 29, 2014 at 11:26

1 Answer 1

3

Just Modify your code as:

 WorkflowServicesManager manager = new WorkflowServicesManager(clientContext, web);
                InteropService workflowInteropService = manager.GetWorkflowInteropService();
                clientContext.Load(workflowInteropService);
                clientContext.ExecuteQuery();

                ClientResult<Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), new Guid(), new Guid(), null);


                clientContext.ExecuteQuery();

This is working for me.

1
  • Yup works now! Thanks! I changed my code to workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), Guid.Empty, Guid.Empty, null); Commented May 29, 2014 at 12:12

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.