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.

You can enroll now !We are giving 30% discount on our Internship Program

Don’t miss the chance to participate in the upcoming Internship Program which will be done using Microsoft Dot Net Web Development Full Stack Technology. The new batch will be starting from May 20, 2024.  We will have most experienced trainers for you to successfully complete the internship with live project experience.

Why to choose Our Internship Program?

Industry-Relevant Projects
Tailored Assignments: We offer projects that align with your academic background and career aspirations.
Real-World Challenges: Tackle industry-specific problems and contribute to meaningful projects that make a difference.

Professional Mentorship
Guidance from Experts: Benefit from one-on-one mentorship from seasoned professionals in your field.
Career Development Workshops: Participate in workshops that focus on resume building, interview skills, and career planning.

Networking Opportunities
Connect with Industry Leaders: Build relationships with professionals and expand your professional network.
Peer Interaction: Collaborate with fellow interns and exchange ideas, fostering a supportive and collaborative environment.

Skill Enhancement
Hands-On Experience: Gain practical skills and learn new technologies through project-based learning.
Soft Skills Development: Enhance communication, teamwork, and problem-solving skills essential for career success.

Free Demo Class Available