Scheduling Workflows With Microsoft Flow

Standard

I recently attended the MVP Summit in Redmond and one of the highlights was a ‘Developers vs Value-Adders’ cage match. Essentially, a business problem was presented and the two sides gave a solution using code and configuration respectively. The referee (me) judged the best response for each problem.

image

One problem that came up, courtesy of Jonas ‘The Friendly Developer’ Rapp was a classic bugbear in Dynamics 365: the issue of scheduling workflows.

image

If you are unfamiliar with the bulk delete job engine trick aka the ‘Wittemann Manoeuvre’, this was a workaround pioneered by MVP veteran Matt ‘Freakin’ Wittemann so many years ago. In short, you used the Bulk Delete scheduler to run a workflow.

So, given Matt came up with this trick about five years ago, is there another codeless way to achieve the same end with the new tools available to us? The answer is Flow.

Scheduling Workflows with Flow: Simple Workflows

When we had the cage match, the specific example raised by Steve ‘Not the Bear from Brave’ Mordue was that of a sales team who needed the notes on a record cleared each week after the sales meeting. Flow lends itself nicely to this because we know we can update records in Dynamics through a Flow Action. So how would this look in Flow?

image

Here it is. First we start with a recurrence Trigger in Flow. This fires however frequently we like and retrieves a list of records using the Dynamics List Records Action. We then loop through the records and update each one with the Update a Record Action. Simple stuff. For the curious, here are the details. The recurrence step looks like this:

image

Here I just have it triggering every hour. It stats when the Flow is first activated. As you can see, you can set the start time to be whatever you like though. Next we have the List Records Action:

image

Here I am simply returning all the Contacts in the system. Finally we go through them and update:

image

image

So I am updating each Contact record and inserting the UTC date and time into the Description field.

Sure enough, the Flow runs every hour.

image

and the Contact records get updated.

image

Mission accomplished. So what if we want to do something more complex than simple record manipulation which is, essentially, all we can do with the Flow Dynamics Actions?

Scheduling Workflows with Flow: Complex Workflows

Flow does not have the richness of Dynamics functionality available to us via workflows so how about instead of trying to replicate the workflow, we simply use the scheduling engine of Flow but call the workflow to do the heavy lifting? The big problem here is there is no Action in Flow to call a workflow but that is ok, we can work around the problem.

The trick is to create a record using Flow and have a workflow trigger off of the creation of the record.

image

The only difference between this Flow and the previous one is that instead of updating the record, we create a new one. Here I have created a Task but this could be any record which is a child to a Contact. The nice thing about Tasks is they are child records to lots of things and it means we automatically have a record in the Activities of the Contact that a Flow has run against our record.

image

image

The Flow has now finished its part in the process and hands over control to the workflow.

image

The workflow waits for the creation of a Task. If the Task is calling the workflow then it fires and goes through its steps. In this case I update the regarding Contact’s Description field with another piece of text.

image

I also mark the Task as complete in my workflow but you could also flag it for deletion via the Bulk Deletion tool.

image

What would be great is if we could call a Flow directly from the workflow which then deletes the Task for us but this is not possible, yet. We could set a flag on the Task and use Flow’s ‘When a Record is Updated’ Trigger, but I digress.

Conclusions

If you are a developer or ‘value-adder’ and you are resisting jumping on board with Flow, you are missing out. While we could schedule workflows in the past through creative solutions like the Wittemann Manoeuvre or throwing code at the problem, Flow provides a straightforward, robust and manageable solution to the problem. To put it simply, Flow is an integral part of the future of the Dynamics platform and to resist it is to be left behind.

Advertisements

6 thoughts on “Scheduling Workflows With Microsoft Flow

  1. What about scalability of this solution though? Is there any concern that you will reach the limit of flows that can be run? Looking at the plans for flows, this could get expensive if that is not factored into the design, especially at a scale of hundreds of thousands run per month.

    Like

    • leontribe

      Yes, the number of monthly runs needs to always be considered with Flow. However, the run is once per hour or, as in the business example, once per week so this would be ok. I do not believe the count is per Contact record as looping through the records is part of the one run.

      Like

  2. Marc

    Would it be possible to trigger the workflow by updating a specific field on the contact and then setting the workflow to start whenever this field is updated?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s