Java Script Task-5 : Call power automate on click on approve button and send the email to parents

 User StoryIf 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

Popular posts from this blog

SSRS User Story-7: Create a SSRS report group by Case, retrieve all work orders and make work orders as sub group, retrieve all bookable resource bookings based on work order. If booking is completed then show the row color as green.

SSRS User Story 2: Generate a report on individual student, if I click on the payment details report in student record. It need to show all the transactions done in current year along with sum. (it should show for each student separately)

SSRS User Story-8: Create a SSRS report on the Opportunity entity, show the source lead and campaign details.