Tag Archives: businessprocessflow

SetProcessRequest and SYSTEM impersonated IOrganizationService

Published / by AK / Leave a Comment

CRM 2016 (Dynamics 365) introduces SetProcessRequest which can be used to activate a business process flow for a given record programmatically. However, it does not always work if IOrganizationService is created by using SYSTEM. To replicate it,

  1. Create a plug-in that executes on Post Operation stage of Create message on an entity (e.g., incident)
  2. Create an impersonated organization service in the plugin
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = serviceFactory.CreateOrganizationService(null);
  3. Use that service to execute the request
    service.Execute(new SetProcessRequest() { ... });

Continue reading