Calling a Javascript snippet from microflow

Hi, I have a use case where firstly, I have to call a javascript method to get a service ticket(String) from a third party application and then store that service ticket in Mendix DB so that I can use it for all of my REST calls to that application. Right now, I'm using the 'Javascript Snippet' module on a page to invoke Javascript. But I want to invoke this through a microflow so as to avoid opening the page first to fetch and store the ticket. How can I achieve this? While searching over the forum, I found ways to do the otherwise(Calling a microflow from javascript, but I want to do the opposite.) Thanks in advance.
4 answers

I don't think that there is an out of the box solution for this. A microflow is always running on the server. Your page executes the javascript code on the client.

But in a microflow, you can call a java action. Is it possible to perform your JavaScript stuff in Java? That might be the easy way.

Does your third party application offer an api to get the service ticket? If so, it might be even easier to call this webservice via the REST/SOPA microflow action.


Hi Niraj,

I've run into this issue a few times myself. One way to get around not being able to call javascript from a microflow is to use a pop up page that you open from the microflow. The pop up page would have the javascript snippet or the html snippet that contains the javascript you want to run, once the page is opened the script will execute and run whatever you need to do. To prevent your users having to close this pop up every time you can add a close page button to it and have your script click the button at the end of it. 

For my use case I had to call a rest service from javascript to receive a cookie in order to authenticate a BI service that we were iframing. The rest call required a jwt token so I had to first run a microflow to retrieve the necessary data and generate the JWT, then I stored that info in a non-persistent entity that I used with the javascript snippet to make the rest call.  


Let me know if you have any questions.


Hope this helps!




Create a entity with an attribute which can hold the key.

Open a page with the editable entity and add the html snippet below.

Let the javascript call the service, write the input to the field and trigger an action button which calls the microflow and uses the entity as input?


Why do you have to call a javascript method to get a service ticket? Isn't it perhaps actually a REST service that is called?

In that case, you can simply use the call REST service action in your microflow.