Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

Stop ExecuteWorkflowResponse from exiting on Exception

$
0
0

Problem: The ExecuteWorkflowResponse call will throw an exception and exit if any of the records experience an issue during workflow execution.

Objective: Have the foreach loop continue to execute the workflow against remaining records in the list of ID's if an exception is thrown for one of the records.  Additionally, have the information around a record's exception logged with the rest of the process logging.

I'm not seeing anything around the webs for doing this, but am hopefully that someone here can point me in the right direction.  Here's the method I'm using to execute the workflow against all records in a view.  Keep in mind that I have a helper method that pulls the view into the process and places all record IDs into a List<Guid> that's then passed into this method...

private bool ExecuteWorkflow(OrganizationServiceContext orgContext, Guid workflowId, List<Guid> recordIds)
{
  bool isSuccess = true;

  try
  {
    foreach (Guid recordId in recordIds)
    {
      ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
      {
        WorkflowId = workflowId,
        EntityId = recordId
      };

      ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)_serviceProxy.Execute(request);

      _flatLog.WriteLine(recordId);
    }
  }
  catch
  {
    isSuccess = false;
  }

  return isSuccess;
}


Viewing all articles
Browse latest Browse all 1000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>