Invoke a Power Automate flow synchronously from a Model Driven App using Actions

Tamilarasu Arunachalam
4 min readDec 10, 2023

--

Photo by Jakob Owens on Unsplash

In this article, I am going to demonstrate on how to use these dataverse custom action to trigger the automated flow in Power automate. Dataverse already has a trigger in place for the event of the action trigger. With this method, we can call a power automate flow synchronously from the model driven app’s command button.

Custom actions are used for creating custom business logics, but they are not invoked automatically. Instead, we can call them inside Workflows, client side scripting, Plugins or Power automate. This custom action may or may not require parameters. There are two types of parameters in action, they are input parameters and output parameters. We can initialize actions either entity specific or global.

  • Create a custom action in a solution by navigating to Settings 🡲 Process 🡲 +New.
  • Add a Process name, category as action, entity as None (global), and Type as New blank process. And click on OK.
  • It will navigate to the classic process creation page. If all the configurations are completed, click on save and activate.
  • Create a new web resource to call the action from the ribbon button. For that, go to the solution 🡲 Web resources.
  • Add name, Display Name, Type as Script(JScript). Click on the Text Editor Button. Add the script below to the editor.
  • For adding the button to a form, we need to go to the make.powerapps.com 🡲 click on the ellipsis (…) near the page that you want to add a button 🡲 Select Main Form and the command editor page opens up.
callAction = {
callGlobalActionFromButton: function () {
'use strict';
var req = {};
req.getMetadata = function () {
return {
boundParameter: null,
operationType: 0,
operationName: "tamil_MyTestAction"
};
};

Xrm.WebApi.online.execute(req).then(
function (data) {
console.log(data.status);
debugger;
},
function (error) {
console.log(error.message);
debugger;
}
);
}
};
  • Add a button by dragging it to where ever you want. Add label, icon, action as JavaScript, add library and function to trigger the button and click OK. Then click Save and Publish.
  • The button got added in the main form as expected.
  • Navigate to the solution page in make.powerapps.com, then click on +New 🡲 Automation 🡲 Cloud Flow 🡲 Automated.
  • A flow creation page pops up, give a meaningful name for the flow and as it is an automated flow we need to choose the trigger. In our case, we need to select When an action is performed trigger from dataverse. Then click in Create.
  • The flow is getting created with the trigger and configure it as like the below image. Give catalog and category as ALL, as it is a global action give Table name as none, select the appropriate action for action name.
  • Add a compose action below the trigger, to get the running user from the trigger. For that, we have to use the expression triggerOutputs()?[‘body/RunAsSystemUserId’]. And Save the flow.
  • To call the action, we need to click on the command button on the main form. If the action gets called, the flow will run automatically by when an action is performed trigger.
  • I clicked the button, the action gets called, and the flow also ran successfully.

Have a good day!

Originally published at https://www.tamilarasu.me on December 10, 2023.

--

--

Tamilarasu Arunachalam

A Software Engineer with experience in developing applications out of Power Platform, majorly on Power Apps and Power Automate. I am a seasonal blogger too.