Please wait, loading...

 

Execute Microsoft Power Automate from Ribbon using JavaScript – On demand Power automate flow using Javascript – in UCI – Replace RibbonAction.js

July 11, 2020

Recently we needed to trigger Power Automate flow from Javascript later after reading my friend's Blog (Ajit Patra Link below) we decided to have a Button which will execute power automate flow using JavaScript.

It was presented as On-demand Power Automate flow to System user

Please go through Referred Ajit’s Blog  for more detail, where he explained how to Execute PowerAutomate on click of a button on the Lead record

Below is Demonstrated in below part

  1. Create Power automate Flow to receive HTTPS Request from Javascript and send Email
  2. Register Javascript
  3. Creating a Ribbon Button on Contact Entity and add javascript action to the button Command and pass PrimaryControl
https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/07/Execute-Microsoft-Power-Automate-from-Ribbon-using-JavaScript-–-On-demand-Power-automate-flow-using-Javascript-–-in-UCI-–-Replace-RibbonAction-js1.jpg?fit=2072%2C1564

Step 1 Create Power automate Flow to receive HTTPS Request from Javascript and send Email

We will create Power automate flow with the trigger “When an HTTP request is received” this will provide us an URL which we will use in our js for execution.

Below are the steps Performed

  1. Create An Power Automate flow, with the trigger ” When an HTTP request is received” 

  2. Use Sample payload to generate the schema , this Schema will be used as Parameter when executing Power automate

  3. Schema generated are available in Actions to be used as dynamic Values

  4.  Now copy the Http Post URL from HTTP action, Also Url will only be available once power automate is saved

Step 2 Register Javascript to Execute Https Request from Microsoft dynamics 365

We will create a simple JS web resource and will use below Javascript Provided by Ajit on his blog: Click Here 

  1. Create New Webreource and use blow Js Code
    function executeRequest(executionContext) {   
    var formContext = executionContext.getFormContext();
        var flowUrl = "Http Post URL";
        var input = JSON.stringify({
            "contactid": formContext .data.entity.getId().replace("{", "").replace("}", "")
        });
        var req = new XMLHttpRequest();
        req.open("POST", flowUrl, true);
        req.setRequestHeader('Content-Type', 'application/json');
        req.send(input);
    }
  2. Save the javascript and add it under the entity Contact

Step 3 Creating a Ribbon Button on Contact Entity and add javascript action to the button Command

  1. Create a new Solution and add the entity where the button needs to be added “testcontact”
  2. Now open the ribbon workbench, If ribbon workbench is not installed, Install Ribbon Workbench from here: Click Here 
  3. Once successfully imported, Open the ribbon workbench and select the Solution created in 1st step

  4. Once loaded we will find 3 Ribbon HOME, SUBGRID, and FORM

  5. Now Drag and drop the button to FORM Ribbon

  6. Give Label, Icon, etc. NOTE IN UCI SVG FORMAT IS SUPPORTED
  7. Now Click on Add new command, Rename it and Click on ADD ACTION

  8. Now search Javascript registered in step 2 and mention function name

    function executeRequest(executionContext) {   
    var formContext = executionContext.getFormContext();
        var flowUrl = "Http Post URL";
    ---------------------------------------------
    ---------------------------
    --------------------------------------------
  9. Most important is PrimaryControl should be passed in Parameter

Thanks

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651
Microsoft Dynamics Community Profile

Learn more