create one powerautomate to send a approved mail to user, call same powerautomate from Javascript on click of approve button

Create one powerautomate to send a approved mail to user, call same powerautomate from Javascript on click of approve button

1)      Open Your Power apps (make.powerapps.com)

2)      Create one Http request.

        Add step for 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 with in that take Xrm Web API code by single retrieve using CRM Rest Builder.


6)      Create one Web Resource and Add Java script code in to this Web Resource

7)      Add this web Resource to Approved Button

Java Script :

function statusApprove(primarycontrol) {

    var formContext = primarycontrol;
    var status = formContext.getAttribute("effizz_checkstatus").getValue();

    if (status != 684200000) {
        formContext.getAttribute("effizz_checkstatus").setValue(684200000);
        // Here 1 is the Option set Approved value
        var Parent = formContext.getAttribute("effizz_parentlvp").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-08.centralindia.logic.azure.com:443/workflows/30632a7d81f645619f4070c72cf4d93c/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=72oHCwwrgjca4MnFkYKQYmAd5-qJ6AXDbcqUoQX3pHY";

                    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);
            }
        );
    }
}

Now Create an 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: Search with schema name check and select the Web Resource Name

Function Name: Enter your Java script function Name

Now Click on Add parameter and choose CRM Parameter 

Inside CRM Parameters take Primary Control 

Click on Publish

In Rest Builder we should do Retrieve Single

Select Contact in Entity

Select Email Address in Field 


Click on create Request then below code will generates


Comments

Popular posts from this blog

If any case created, then check for the same user how many cases are created with in 30 days, if more than 2 and less than 5 send a mail to team lead, if more than 5 and less than 9 then send a mail to manager using power automate.

Create approve & reject ribbon buttons, once click on approve it should change the status field to approve.If clicked on reject it should change to Reject. Based on status field change trigger work flow to send a email to stating request is approved/Rejected.

How to get and set values in plugins?