5. call power automate on click on approve button and send the email to parents

 

User Story:  call power automate on click on approve button and send the email to parents

1.     Create automated flow to send an email to parent when record was approved

2.     Using Rest builder Generate a code to retrieve parent email id from parent lookup field

3.     Write a JavaScript function to trigger automated flow and place it in web resource

4.     Call the JavaScript function from approve button using XRM Toolbox

    Requirements: JavaScript and Power Automate

Create automated flow to send an email to parent when record was approved and copy the URL

https://www.blogger.com/blog/post/edit/8622276778631685188/8040929121398844401





URL: https://prod-176.westus.logic.azure.com:443/workflows/1d14a9d00d0b474eb1f5b5047759bf13/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=OsJp_eOrOCydxbt7QxlglDcfKUTj_f3DLncZ2FRIhyE

Using Rest builder Generate a code to retrieve parent email id from parent lookup field

Xrm.WebApi.online.retrieveRecord("contact", "00000000-0000-0000-0000-000000000000", "?$select=emailaddress1").then(

    function success(result) {

        var emailaddress1 = result["emailaddress1"];

    },

    function(error) {

        Xrm.Utility.alertDialog(error.message);

    }

);



Write a JavaScript function to trigger automated flow and place it in web resource

function powerflow(primarycontrol) {

 

    var formContext = primarycontrol;

    var parentField = formContext.getAttribute("crb67_parent").getValue(); 

    (parentField != null)

    {

        var name = parentField[0].name;

        var id = parentField[0].id.replace("{", "").replace("}", "");

 

        Xrm.WebApi.online.retrieveRecord("contact", id, "?$select=emailaddress1,fullname").then(

            function success(result) {

                var emailaddress1 = result["emailaddress1"];

                var fullname = result["fullname"];

                if (emailaddress1 != null) {

                    var req = new XMLHttpRequest();

                    var url = "https://prod-176.westus.logic.azure.com:443/workflows/1d14a9d00d0b474eb1f5b5047759bf13/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=OsJp_eOrOCydxbt7QxlglDcfKUTj_f3DLncZ2FRIhyE"

                    req.open("POST", url, true);

                    req.setRequestHeader('Content-Type', 'application/json');

                    req.send(JSON.stringify({

                        "Email": emailaddress1,

                        "Name": name

                    }));

                }

            },

            function (error)

            {

                Xrm.Utility.alertDialog(error.message);

            }

        );

    }

}

Call the JavaScript function from approve button using XRM Toolbox



 Out Put:




Comments

Popular posts from this blog

2. On Click of case Reject button, show popup with reject reason text, once filled and submitted, reject reason field should get filled and case should be in read only

1. In Case Entity, based on Incident Type selection, filter the case category using the category-incident master entity

8. On selection of asset in case entity, read the project in asset, project start date and end date from project entity, set the dates on case entity from as project start date and end dates