PowerApps Using JavaScript
About the Author: Manish Luhana
Microsoft business applications specialist and certified trainer.
Categories: Power Automate, Power Platform0 CommentsPublished On: 29 December 2021

compose

In this article, I’ll show you how to use Dynamics 365 JavaScript to contact Power Automate. Let’s say I want to use JavaScript to deliver a PDF containing account information when a new account is created in the system.

To do so, follow the instructions below:

Step 1: Create a flow using the trigger “When a Request Is Received” in the Power Automate Open Power Apps solution. Use the following JSON Payload: {“Name” : “MSFT”,”Email”: msft@gmail.com}

configure-power

Then, to assemble the request parameters into an HTML format, add a compose action.

compose-2

Add another action after the compose action. Muhimbi Connector converts HTML to PDF. You must subscribe for Muhimbi. Select the Concert action’s output in the HTML section.

convert-html

Add a send email operation with a PDF attachment.

sent-an-email

Save the flow now.

Step:2 – Enable Web Resource for Dynamics 365

Build a JavaScript Web resource and paste the script below into it.

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 equivalent to the one generated by FLow.

The account form may be used to call the Web resource method name.

configure-event

The event is on save. As a result, when we create an account and save it, the flow will call and send an email with a PDF attachment.

inbox-test

tech mentor sidebanner
  • Continue reading
  • Continue reading
  • Continue reading
  • Continue reading
  • Continue reading

Leave A Comment