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.
One problem that came up, courtesy of Jonas ‘The Friendly Developer’ Rapp was a classic bugbear in Dynamics 365: the issue of scheduling workflows.
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?
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:
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:
Here I am simply returning all the Contacts in the system. Finally we go through them and update:
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.
and the Contact records get updated.
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.
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.
The Flow has now finished its part in the process and hands over control to the workflow.
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.
I also mark the Task as complete in my workflow but you could also flag it for deletion via the Bulk Deletion tool.
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.
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.