Synchronous and On-demand Flow inside Model Apps!

Let me first start of with wishing you all a happy new year. I hope you all had a lovely holiday season. I enjoyed a few days off and spent it with my family. On to the subject at hand, synchronous and On-demand Flow in Model Apps. As most of you know Microsoft prefers us using Power Automate Flow instead of Classic Workflow. However there are still some gaps in functionality between the two.

When developing solutions I follow Microsoft guidelines as much as possible. This ensures that the solution is durable and I create the least technical debt. With that in mind, I now keep away from Classic Workflow and use Flow whenever I can. Last few weeks I tried to fulfill business requirements within these restrictions.

On-demand Flows

None of the two CDS connectors provide an action to create a synchronous and On-demand Flow. In this post I will focus on the On-demand option in relation to the CDS Current Environment connector. The CDS Current environment connector does not have the option to create end-user On-demand Flows. Specifically the “When a record is selected” trigger is not available. Which really is a shame, because as a consultant I want to create On-demand Flows in the development environment and deploy them to the production environment. I do not want to manually export and import Flows or fix connections after each solution import. So I started to think about the most elegant way to fulfill my requirement and man was I in for a treat!

Run Flow From Model-App
Run Flow From Model-App

I almost instantly thought of creating a “When a HTTP request is received” Flow. Then add them as a button to the ribbon using the RibbonWorkBench. This solves my requirement as I can add this to a solution and it acts as an On-demand Flow. While doing some research I opened door number 21 of the MVP advent calender. I couldn’t believe what I saw, it was exactly what I needed! Scott Durow released a new version of his SmartButtons. In this version he added support for “WebHooks” that can be used to trigger HttpRequest Flows!

When a HTTP request is received

Let’s start creating a SmartButton! If you want to see this example inside a model app, download the solution here.

  1. First a quick walkthrough on how to create a basic “Webhook” flow. Create a flow inside your solution and pick the “When a HTTP request is received” trigger. After saving the Flow we can get the URL to use in our button.
    Create the body using “Generate from sample” with the following json:
    {
    “id” : “00000000-0000-0000-0000-000000000000”
    }
  2. Add the actions you need using the CDS Current Environment connector. For this example I update the Main Phone of the record we are currently editing with number 4567. Just because it needs to be done. Consider it an AVG necessity. It absolutely was a requirement. I’m not being lazy here, I promise!
  3. After adding all the actions, send a “200 OK” response to the caller. You can extend the response to add feedback of your flow to the end user pushing the button.
When a HTTP request is received
1. When a HTTP request is received
Update record with the Current Environment Connector
2. Update record with the Current Environment Connector
End your flow with a 200 status response
3. End your flow with a 200 status response

To use SmartButtons install the solution provided here. This solution contains scripting that executes the button commands. Keep in mind that every environment needs to have this solution installed. Launch the RibbonWorkBench plugin from the XrmToolBox. Connect to an environment and if everything is configured correctly the option to create SmartButtons appears in the bottom left corner.

Smart Buttons inside the Ribbon Workbench
Smart Buttons inside the Ribbon Workbench

Add the Run Webhook button to your Ribbon. Fill in the title, the URL of your webhook (the URL of the Flow we created earlier) and you are good to go! Sometimes it is just that easy!

Run Webhook parameters
Run Webhook parameters

But Ben, a fixed URL defeats the purpose of the CDS Current Environment connector!

You are absolutely right. When deploying the solution to the production environment the “When a record is selected” Flow will have a different URL for this environment. Luckily Microsoft is working on a way for environment specific variables. I can create a variable for the “When a record is selected” Flow. In this variable I enter the URL of the trigger specific for that environment.

The code is ready!

And Scott not only has the same idea, he already has the code! When environment variables become general available Scott will update his SmartButton solution.

The end result is synchronous?!

Check out the end result in the video above. I am very pleased with this. We have created an synchronous and on-demand Flow with the Current Environment connector. And it even refreshes the form afterwards. Of course this is scripting that does the magic, however it is synchronous none the less! This can be an improvement compared to the usual On-demand Flows. And it most certainly is for this scenario.

Now I cannot take credit for this. Scott has made this available to the community. So if you enjoy this, go ahead and tell him! Check out his blog for more examples of SmartButtons.

Are synchronous Flows even coming?

I understand the product team’s hesitations when implementing synchronous Flows as synchronous workflows heavily impacts performance. Of course they do not want to introduce the same functionality with the same pitfalls. However there are a lot of business requirements synchronous workflows solves. Especially for citizens developing model-apps.

The lack of communication on this subject worries me. I am afraid to say this out loud, but I think Microsoft might be considering not implement synchronous Flows. I do not have evidence to support this claim. So let’s continue hoping synchronous Power Automate Flows become available soon, just as they are in Canvas Apps.

Leave a Reply

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