Run Power Automate using JS
Step 1: Create Power Automate
Step 2: Use below action.
Sample Json:{ "workorderid": "a2e36a68-3d7f-4177-be25-aff61ddb13d0"}
Sample Body:
{
"type": "object",
"properties": {
"workorderid": {
"type": "string"
}
}
}
Step 3: Do further steps for action.
Create button:
Step 4: Last add response.
function Runflow(orderid) {
debugger;
if(orderid != null)
{
orderid=orderid.replace("{", "").replace("}", "");
}
var flowUrl = "<Powerautomate link>";
/// Request preparation
var input = JSON.stringify({
"orderid": orderid
});
var req = new XMLHttpRequest();
req.open("POST", flowUrl, true);
req.setRequestHeader('Content-Type', 'application/json');
////Request processing setup
req.onreadystatechange = function () {
debugger;
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = this.response;
alert(result);
}
else if(this.status != 200){
alert(this.statusText);
var result = this.response;
alert("Error" + result);
}
}
};
req.send(input); /// Request sent
}
Comments
Post a Comment