How to Trigger a Microsoft Flow from a Custom Button in Dynamics 365

Adam Murchison, 23 July 2019

When using Microsoft Flow the out-of-the-box button is nested under the ‘Flow’ section and is not easy to find nor is it customizable. Triggering the flow using a ‘Flow Button’ makes the button appear under the ‘Run Flow’ branch which is a nested button that is unintuitive for users.

It is much nicer to have your own customized button to trigger a flow and to do this is surprisingly easy.

image

Creating a Button in Dynamics 365

I created my button using the Ribbon Workbench which calls a command. We’ll go into detail what this command does later on. Here’s my button.

image

Create your Flow

Below is the flow I want to call from the button in Dynamics 365. As you can see there’s a trigger that says ‘When a HTTP request is received’. Once saved the URL will generate for this endpoint and you can define a JSON object that will be received by the Flow. In this example I’m passing through a ‘path’ to the ‘Create File’ method. We’ll keep this blog on the topic of calling Flows from a Dynamics 365 but there’s plenty of information out there on how passing parameters to Flow works. The Flow is simply going to create a File under the path and then send a response with an object.

image



JavaScript

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
sendFlowRequest = function () {
    var pathObj = { "path": "/Account/" };

    parent.$.ajax({
        type: "POST",
        url: https://zzz.logic.azure.com:443/workflows/zzzzzzz/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=,
        contentType: 'application/json',
        data: JSON.stringify(pathObj),
        success: function () {
            alert("success");
        }
    });
}


Above is the code I used to call my Microsoft Flow. The code passes through a ‘pathObj’ which is the object that the request endpoint created in Flow is expecting. The Flow will now create a File under the ‘/Account/’ path.

Response

image

There you have it, using the out of the box way of calling Microsoft Flow’s from the ‘Flow Button’ should not be defaulted to because calling it from your own custom button is surprisingly easy.