Let’s rule the business process.. with a workflow!

By | June 21, 2017

I was reading a recent post by Dynamics team – they are talking about different ways to manipulate business process stages in Dynamics 365 there:

Best practices for automating business process stage progression in Dynamics 365

It’s a great article, and it has some interesting insights. What definitely caught my attention is that, it seems, we should be able to manipulate business process flows using the workflows now. Isn’t it what we always wanted to do? Imagine how you could verify some conditions in the workflow and move the process flow to the right stage depending on whether those conditions have been met or not. That would add quite a bit of automation to the whole process.

And, it seems, it’s really doable now. I did manage to make it work – just keep reading and you’ll find out how. However, keep in mind this whole article applies to the post fall 2016 versions of Dynamics 365.

First, here is what we need to know:

  • For each business process flow there is an entity in Dynamics now. You can give it a name when creating a business process flow
  • That entity, among other fields, has two lookup fields: a lookup to the main entity (the one for which this process flow is supposed to be running), and a lookup to the process stage entity
  • Every time a process is activated, a new record of that entity type is created
  • Active Stage lookup field in that record gets updated every time we move the process through the stages

To test how it works, I did set up a new entity and a new business process. Here is how the solution looks like:

  • Process Demo entity is the main entity which will have a process etc
  • Main Demo is the entity that was created for the Main Demo business process(there an entity per process, remember?)
  • There is Main Demo process
  • And there are a couple of workflows – I’ll explain what they are for down below

It turns out we can really use business process entity in the workflows just like we can do it with any other entity. However, there is a little problem there. Business process entity is related to the main entity as N:1 (many process instances, one main entity). Which means we can’t really access active business process from a workflow running on the main entity (it would be like asking a workflow running on the account record to access a particular contact linked to that account).

However, this relationship is, really, 1:1 rather than N:1. At any time, only one active process of that particular type can be associated with the main entity.

In other words, if we wanted to make it work, we would need to add a lookup from the main entity to the process entity. And that’s the first step – let’s add a lookup:

 

Once there is a lookup, we can use it in the workflow running for the main entity. Problem is, we still need to have some value in that lookup first.

That’s what one of those workflows is for:

BTW, do you see something unusual there? Where did that new trigger called “process is applied” come from? It seems to be one of the features of this new version of Dynamics, and it’s exactly what we need. This workflow will start whenever a process is applied to the main entity, and it will populate the lookup field on the main entity.

Once it’s done, we can use that lookup value in the workflows running for the main entity.

That’s what the second workflow is for:

The workflow will run when a new record is created or when a checkbox field is checked off. It will verify whether the checkbox is selected, and, if yes, it will modify active process stage.

And that’s, actually, it. I just got a workflow that can change active stage of the business process!

PS. Quite frankly, this was a little condensed version of how it all happened, so, here is what you’ll find in the next post:

  • I’ll provide a link to the unmanaged solution file
  • I’ll describe a few error messages I’ve run into while working on it

See it here: http://www.itaintboring.com/dynamics-crm/lets-rule-the-business-process-part-2/

3 thoughts on “Let’s rule the business process.. with a workflow!

  1. Joel Lindstrom

    good post–your approach works, but it is not the most efficient way to do it. For example, your approach of adding the lookup field precludes you from using multiple process flows on the same entity.

    See https://blogs.msdn.microsoft.com/crminthefield/2017/12/18/automate-business-process-flow-stages-using-workflows/#comment-48546. This is the best way to do it.

    All you have to do is create a workflow on the entity for your business process flow and trigger it on change of the related entity values

    Reply
    1. Alex Shlega Post author

      Hi Joel,

      absolutely agree, it’s a better way. There are 6 months between those posts, though, and, at the time of writing this one, I did not even know business process entities have special triggers. Actually, I did not know we can trigger those workflows on the change of related entities until today:) Thanks for pointing it out.

      Reply
  2. Bob Nuget

    Thanks, I was trying to figure out how to set the lookup after placing it. Life saver.

    Reply

Leave a Reply

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