Call Power Automate or Microsoft Flow from JavaScript – Dynamics 365 CE

Hi Everyone,

We all know how Power Automate or Microsoft Flows are changing the way we design the things in Dynamics 365 CE. Recently, we got a requirement to call Microsoft Flow from a button click on Dynamics 365. Here is the way we did using JavaScript.

Let’s create a flow as below.

1) Take the trigger as HTTP Request received.


2) Generate Schema accordingly to your input, I just have AccountID as an Input so taken JSON as below to generate schema and declare the method as POST.
{“AccountId”: “abc”}


3) I just added one step of Variable as once the flows is triggered from the JavaScript, we can add the steps as per our requirement.


4) Save the flow and get the URL from HTTP Trigger (first step)


5) Here is the JavaScript code for calling flow.

function callFlowFromJavaScript() {
    var flowUrl = "FLOW URL";
    var input = JSON.stringify({
        "AccountId": "475b158c-541c-e511-80d3-3863bb347ba8"
    });
    var req = new XMLHttpRequest();
    req.open("POST", flowUrl, true);
    req.setRequestHeader('Content-Type', 'application/json');
    req.send(input);
}

To Configure Flow URL in a best way, you can read this Post.

Hope this helps.


Happy 365’ing
Gopinath.

Invalid type. Expected String but got Null or Invalid type, Expecting Object but got Null – Microsoft Flow/Power Automate

Hi Everyone,

Today I was working on flows and all of a sudden flow started failing with the below error at Parse JSON step.

“Invalid type. Expected String but got Null”

However, was able to understand the issue after checking the input that was passed to Parse JSON step. One of the property value is coming as Null.

The fix is easy, we just need modify the Schema of Parse JSON.

instead of “type”: “string” make it as “type”: [“string”, “null”] to handle null values.

Hope this helps.


Happy 365’ing
Gopinath.