Skipping process initialization on create

By | June 21, 2018

We had a scenario where we did not want to initialize a BPF when a record is created – basically, those were records for which it would take some time before anybody would really need to start looking at them. Until that moment, they would be staying “dormant” in the system, and, then, once they’ve been marked as “ready”, the process would really start.

So, if we did start the BPF right away, we would end up with incorrect process duration since all those records could be spending days or weeks in the “dormant” state, and, then, they could be processed in just a few days once they are activated.

Anyway, somehow we had to prevent Dynamics from automatically initializing a BPF for those records.

Turned out there is an extremely simple solution that’s been mentioned here:

https://blogs.msdn.microsoft.com/crm/2017/10/03/handling-business-process-flows-bpfs-on-record-create/

We just had to set processid to Guid.Empty on all those records initially, and that’s just the right task for a simple plugin:

public void Execute(IServiceProvider serviceProvider)
  {
             IPluginExecutionContext context = (IPluginExecutionContext)
                 serviceProvider.GetService(typeof(IPluginExecutionContext));
             Entity target = (Entity)context.InputParameters[“Target”];
             target[“processid”] = Guid.Empty;
  }

Register that plugin on pre-create of the entity, and that’s it.. Every new record will get Guid.Empty for the processid, so Dynamics will skip initializing the BPF.

Leave a Reply

Your email address will not be published. Required fields are marked *