Click here to Skip to main content
15,887,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,
I am trying to start share-point workflow using CSOM(Client side object model) by following means of code. But i got the following error from the line mark in comment. Please help me to figure out this error.

Error :- Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. "GetWorkflowDeploymentService
new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager()
"



C#
 public bool StartWorkFlow()
 {
    private ClientContext _sharepoint = null;
    private Web _web = null;
    _sharepoint = new ClientContext("http://sharepoint/sites/dmdev/");
    _sharepoint.AuthenticationMode = ClientAuthenticationMode.Default;

    string workflowName = "UpdateDealStatus";

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

  // connect to the deployment service
   var workflowDeploymentService = workflowServicesManager.GetWorkflowDeploymentService();

  // get all installed workflows
  var publishedWorkflowDefinitions =    workflowDeploymentService.EnumerateDefinitions(true);
            _sharepoint.Load(publishedWorkflowDefinitions);

   try
   {
      _sharepoint.ExecuteQuery();//Error thrown from this line
   }
   catch (Exception ex)
   {
                
                
   }

   // find the first workflow definition
   var firstWorkflowDefinition = publishedWorkflowDefinitions.First();

   // connect to the subscription service
   var workflowSubscriptionService = workflowServicesManager.GetWorkflowSubscriptionService();

   // get all workflow associations
   var workflowAssociations = workflowSubscriptionService.EnumerateSubscriptionsByDefinition(firstWorkflowDefinition.Id);
   
   _sharepoint.Load(workflowAssociations);
   _sharepoint.ExecuteQuery();

   foreach (var association in workflowAssociations)
   {
       Console.WriteLine("{0} - {1}",
       association.Id, association.Name);
   }
    return true;
}
Posted
Updated 1-Mar-16 13:15pm
v2
Comments
Richard MacCutchan 2-Mar-16 4:48am    
The error message tells you what is wrong. Use your debugger to find out why the call to GetWorkflowDeploymentService does not return a valid object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900