Bhubaneswar, Odisha, India
+91-8328865778
support@softchief.com

Call Power Automate using JavaScript from Dynamics 365 Forms

Call Power Automate using JavaScript from Dynamics 365 Forms

In this post I will explain about the steps to call Power Automate from Dynamics 365 JavaScript. Let us take a scenario, I want to send a PDF with Account information when an account is created in the system using JavaScript.

For this follow below steps:

Step:1 – Configure Power Automate

Open Power Apps solution and add a flow with trigger “When a Request Received”. Use JSON Payload as given below:

{“Name” : “MSFT”,”Email”: “msft@gmail.com”}

Next add a compose action to compose the request parameters into a HTML format.

After the compose action add another action Convert HTML to PDF using Muhimbi Connector. You need to signup for Muhimbi. In the HTML section choose the output of Concert action.

Now add send email action with attachment as PDF.

Now save the flow.

Step:2 – Configure Web Resource for Dynamics 365

Configure a JavaScript Web resource and add below script.

function callFlow(executionContext)
{
    var formContext = executionContext.getFormContext();
    var accountName = formContext.getAttribute("name").getValue();
    var email = formContext.getAttribute("emailaddress1").getValue();
    
    var params = {
        "Name":accountName,
        "Email":email
   }

    var url = "https://prod-189.westus.logic.azure.com:443/workflows/75b05db9981e41d89a6887fff03c1fee/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=uGEet3rej2Z1xWu6GS-8WTPUF0sRnmRsGaXQGSpz1yw";
    var req = new XMLHttpRequest();
	req.open("POST", url, true);
    req.setRequestHeader('Content-Type', 'application/json');
    req.send(JSON.stringify(params));
    Xrm.Utility.alertDialog("Flow initiated. The PDF will be sent soon.");
}

The URL should be the same as the URL generated in FLow.

Call the Web resource method name from account form.

The event is OnSave. So when we create an account and save it the flow will call and send email with PDF.

Follow my blog for more trending topics on Dynamics 365, Azure, C#, Power Portals and Power Platform. For training, Courses and consulting, call to us at +91 832 886 5778 I am working more for community to share skills in Dynamics 365 and Power Platform. Please support me by subscribing my YouTube Channel. My YouTube Channel link is this : https://www.youtube.com/user/sppmaestro

Hope this helps.