Trigger Power Automate Flow using JavaScript – Bi-Directional

Hi All, 

This blog will be a continuation of my previous blog –  Trigger Power Automate Flow using JavaScript – Uni Directional

Now, feedback is essential when sending a request to determine whether it was successfully performed or failed somewhere. 

You can accomplish this by forwarding a response back from where the flow was invoked. 

I’ll use the same situation as in my previous blog, where I send a notification by greeting a person’s name if exists, or else I will greet a friend. 

Check out my previous blog to learn how to build your Flow and JavaScript. 

Steps to pass the response back within Flow 

Step 1: Add a response that will be sent back from where the Flow was invoked. 

Quick Tip: I am checking if ‘Name’ is present in my dynamic content. If yes, then greet the person else greet a Friend 

Formula: if(contains(triggerBody()?[‘DynamicData’], ‘Name’), triggerBody()?[‘DynamicData’][‘Name’], ‘Friend’) 

Steps to add into the JavaScript

Step 1: Initially we created JS to trigger the flow, now we will add the code snippet to accept the response from Flow.

Add the following Code:

var TriggerFlow = 


    Main: () => 


        var formContext = executionContext.getFormContext(); 

        //Strict Defined Parameters 

        var RecordID ="{", "").replace("}", ""); 

        var EntityName =; 

        //Dynamic Parameter - Sample Data 

        var DynamicValues = {Name: "Ethan", Operation: "One Way Power Automate trigger"}; 

        //Find Plural Logical Name of the Entity and Call Flow 

        Xrm.Utility.getEntityMetadata(EntityName, "").then( 

            function (result) 


                TriggerFlow.CallFlow({logicalEntityName: result.EntitySetName, CurrentRecord: RecordID, DynamicData: DynamicValues}); 


            function (error) 






    CallFlow: ({logicalEntityName, CurrentRecord, DynamicData}) => 


        var flowUrl = ""; 

        var inputdata = JSON.stringify({ 

            "EntityName": logicalEntityName, 

            "RecordID": CurrentRecord, 

            "DynamicData": DynamicData 


        var req = new XMLHttpRequest(); "POST", flowUrl, true); 

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



        req.onreadystatechange = function () { 

            if (this.readyState === 4) { 

                req.onreadystatechange = null; 

                if (this.status === 200) 


                    var result = this.response; 

                    alert("" + result); 


                else if(this.status === 400) 



                    var result = this.response; 

                    alert("Error" + result); 






Step 2: Trigger the JS and watch the output I get as Alert (I have used the console page to trigger my JS for example purposes)

Hope this helps in achieving a response from the Power Automate Flow!

Share Story :