Java Script Task-5 : Call power automate on click on approve button and send the email to parents
User Story: If you click on the approve button approve status should get approved and send the mail to parents by using power automate achieve this scenario
1) Open Power apps (make.powerapps.com)
2) Create one Http request
· Add step as Send Email
3) Create One Approve Button By using Ribbon work bench
4) By using CRM Rest Builder retrieve the Parent Email address
5) Write a Java Script Code by using CRM Rest Builder provided Code
In java script code:
· Retrieve the approval status
· Give the null check as if approval status is not equal to Approved
· Then set the value as Approved and retrieve the Parent
· Here again give the null check as if parent email !=null then by using XML Http request send the mail to parent.
6) Create one Web Resource and Add Java script code in to this Web Resource
7) Add this web Resource to Approved Button
Create one Approve button
When you click on Approve button Approve status will update to Approved
Click on Button command then below window will opened
click on Action and enter
Library: Enter Web Resource Name
Function Name: Enter Java script function Name
Click on Add parameter and choose Primary control
Click on Publish
Code:
Click on create Request then below code will generates
function statusApprove(primarycontrol) {
var formContext = primarycontrol;
var status = formContext.getAttribute("effi_approvalstatus").getValue();
if (status != 1) {
formContext.getAttribute("effi_paapprovalstatus").setValue(1);
// Here 1 is the Option set Approved value
var Parent = formContext.getAttribute("effi_parent").getValue();
var name = Parent[0].name;
var id = Parent[0].id.replace("{", "").replace("}", "");
Xrm.WebApi.online.retrieveRecord("contact", id, "?$select=emailaddress1").then(
function success(result) {
var Email = result["emailaddress1"];
if (Email != null) {
var req = new XMLHttpRequest();
var url = "https://prod-15.centralindia.logic.azure.com:443/workflows/41cead4e35cf400e92797cfe8f5478b1/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=QR6SixpZrLp4OxPxxQsSR13cOcmPWOoI5xBlnqDwb-k";
req.open("POST", url, true);
req.setRequestHeader('content-Type', 'application/json');
req.send(JSON.stringify({
"Parent": name,
"Email": Email
}));
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
}
Comments
Post a Comment