We all know that calling the action from a button in CRM can be easily achieved by using JavaScript.
But, what if you want to call an action from the PowerApps portal custom button. Since there is no direct way of calling the action in the PowerApps portal, we can achieve this using Ms flow. Let see how we can achieve this.
Prerequisites
- Power Automate
Scenario
We have a custom button on the entity named “Duplicate” when the user will click this button duplicate records should get created.
Steps
- Add a custom button on which you want to call the action
Code: $('#UpdateButton').after('<button type="button" id="CloneProduct" onclick= duplicateRecord() class="btn btn-warning">Duplicate</button>');
- Create MS flow (Power Automate).
- Make sure you create MS flow from the solution (this is a very important step)

- Go to +New –> Flow

- Search for the “Request” trigger and select that.
Request –> When a HTTP Request is received

- Select “When an HTTP Request is received”

- Click on “use sample payload to generate schema”

- Enter JSON (here you must pass input parameters which are required for your action)
My action requires only the GUID of record, so I am passing that

{
"vv_hardwarespecificationsid": "787F593F-B48B-4DC0-831A-0463EDD9631C"
}
- Click on Done
- Click on “+ New Step”
- Search for Common Data Service (current environment) connector and select that.

- Search and Select “Perform a bound action” in that connector

- Enter below details in action

Entity Name: select the entity on which action is registered
Action Name: select the action
Item ID: Guid of the record (select from the previous step)
NOTE: if you don’t create flow inside the solution you won’t be able to see this Action.
- You can also send the response back in PowerApps Portal by adding “Response” action


- Save the flow after saving the flow copy the “HTTP POST URL” this we will use in PowerApps portal to call this flow.

Your flow should look like below:

- Once your flow is ready, add below JavaScript on the webpage of the portal to call the flow
Code:
duplicateRecord():
- this function will trigger when the user will click on the “Duplicate” button
- we are getting the GUID of record from URL.
- Call the “callFlowAction()”method
callFlowAction():
- this method triggers the MS flow
- paste the URL which you have copied from the flow.
$(document).ready(function(){
$('#UpdateButton').after('<button type="button" id="CloneProduct" onclick= duplicateRecord() class="btn btn-warning">Duplicate</button>');
})
function duplicateRecord() {
let searchParams = new URLSearchParams(window.location.search);
if (searchParams.has('id') === true) {
id = searchParams.get('id');
}
callFlowAction(id);
}
function callFlowAction(id) {
var postMethod = {
"url": "https://prod-03.centralindia.logic.azure.com:443/workflows/32063cc9e9594a749912e7d81f5709f6/triggers/manual/paths/invoke?api-version=2016-06",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({ "vv_hardwarespecificationsid": id }),
};
$.ajax(postMethod).done(function (response) {
console.log(response);
alert("Record is Duplicated Successfully");
});
}
Once you add the code try to create duplicate records by clicking on custom “Duplicate” button


Summary
I hope this blog helps you to call any action from PowerApps portal