Dynamics 365 Business Central: Can we start Power Automate flow via AL? Yes, but……

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about a question I was asked recently, can we start Power Automate flow via AL?

Power Automate empowers customers to create their own workflows using a low-code/no-code approach with a vast amount of connectors that make it easy to integrate systems.

With Business Central 2022 wave 1 (BC20), every page that runs in the context of a data table now features a new Automate group in the action bar.
More details:

And in Business Central 2022 wave 2 (BC21), actions added in the new Automate action group in the action bar now rely on personalization or designer, so that they can be moved, promoted, or hidden.
More details: Business Central 2022 wave 2 (BC21) new features: Personalize and design the Automate action group in the web client – The customaction keyword

But you should have noticed that this can only be done by starting the flow via an action. Is it possible to start the flow through AL? For example, after the OnAfterValidate() trigger is executed. Yes, it is possible, but like doing it in action, it cannot be fully automated. Let’s see more details.

I created a very simple flow that just sends a message to a Teams channel.

If you go to the flow details page, you can find the complete URL of this flow. (Including Flow Environment and Flow Id)

https://make.powerautomate.com/environments/Default-7e47da45-7f7d-448a-bd3d-1f4aa2ec8f62/flows/14ad7d29-6070-4275-a07e-12404575d5c8/details?v3=false

Delete details?v3=false (the part after details), add run. We will use this URL in AL.

https://make.powerautomate.com/environments/Default-7e47da45-7f7d-448a-bd3d-1f4aa2ec8f62/flows/14ad7d29-6070-4275-a07e-12404575d5c8/run

The rest is very simple, we just need to use System.Hyperlink(Text) Method in the code to run this URL. For example,

This URL will redirect you from the flow overview directly to the flow start page.

Then you can run the flow.
Test video:

Very simple, but please note that this is the same as running the flow from an action, you need to manually click Run flow.

The next question is whether the “For a selected record (V3)” trigger is still valid. For example,

Unfortunately, this will give the following error message.

The input body for trigger ‘manual’ of type ‘Request’ did not match its schema definition. Error details: ‘Required properties are missing from object: entity.’.

So this approach is only useful when dealing with data other than BC, or when dealing with fixed data. For example,

Great, give it a try!!!😁

PS:
Dynamics 365 Business Central: How to hide Power Automate action group for some users by permission set

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL