Use microflow return value in widget

Hi all, I've been dabbling in widget development for the last time, but I'm running into an issue at the moment. In my widget properties I have the ability to select two microflows which return String values. I want to use these values in my widget; set them in a variable so that I can send them to yet another function. I've looked at the CustomString widget source, which uses a callback to set the HTML with the returnedString. However, I can't manage to rebuild this using my specs. I've also seen another question here on the forum which redirects to a 4.0 How-To, which uses a completely different setup (dojo.fromJson, mx.processor.action and such), so I'm not really sure whether that's up to date for Mx 5.19+ Examples. Please bear in mind I have two (seperate) microflows selected which both return (different) String values. My JavaScript code: var lat = this._getLat(); getLat(): _getLat: function(callback) {{ params : { actionname :, applyto : "selection", guids : [this._contextObj.getGuid()] }, store: { caller: this.mxform }, callback : dojoLang.hitch(this, this._processMF, callback), error : dojoLang.hitch(this, function(error) { alert(error.description); mendix.lang.nullExec(callback); }), onValidation : dojoLang.hitch(this, function(validations) { alert("There were " + validations.length + " validation errors"); mendix.lang.nullExec(callback); }) }); }, The callback (_processMF) _processMF: function (returnedString, callback) { logger.debug( + "._processSourceMFCallback"); mendix.lang.nullExec(callback); var processed = dojo.fromJson(returnedString.xhr.responseText); logger.debug(processed['actionResult']); return processed['actionResult']; }, As you can probably see I'm not really sure what to do from here. The customString widget immediately uses the returnValue, but I don't want to do that, and the tutorial seems outdated? Any tips?
5 answers

Hi Paul,

I'd have to see the complete code to see what it does. From what I see in the snippet above, I have the following points:


var lat = this._getLat();

will not work. The is asynchronous, so the function ._getLat() will not return anything.


callback : dojoLang.hitch(this, this._processMF, callback),

will result in _processMF being called after the microflow has been executed. If you add the extra parameter (callback), this will be the first parameter that is used in the function that is being called (in this case: _processMF). That being said, it means you have to make sure that in this function, the callback is the first parameter. The microflow returns a string, so that becomes the second parameter in your callback function (of Thus:

_processMF: function (callback, returnedString) {



So why do we pass this callback everywhere? That's because this callback function initially comes from update: function(obj, callback), where the callback is a function that is being passed by Mendix/Dojo (need to look this up). This callback function, when executed, essentially tells the page "hey! I have rendered my widget". So you want to make sure that this callback is being called AFTER you have complete rendered your widget (or updated your rendering).

Anyway, I'd have to see the complete code of the widget js to see what you try to accomplish. You could share it as a Gist if you want. You know where to find me on Github :-)


I'll post this in an answer, since the response is to long for a comment, but I was able to get it working by changing the callback functions of the microflows. These link to the same function and the processing continues from there.. Atleast my variables have data now.. Onto the next challenge :-)

Looking at the dojo.hitch documentation got me in the right direction!

Thanks Jelte and Chris for thinking with me!


Is there a way to do this in the new Pluggable Widget?
Currently I am using mendix v8.5.6



callback     : dojoLang.hitch(this, this._processMF, callback),


callback     : dojoLang.hitch(this, this._processMF),

and remove the callback parameter from processMF.


Hi Jelte,

Thanks for your answer and explanation. Let me try to explain it a bit more. What I want to do is have the microflows return a latitude and longitude value from a microflow ( so that the user is free to use what logic he wants to get this data) and use that value to get a weather forecast based on an API call.

I have put some extra variables in there that might be unneeded, but I'd like to think that I'd learn something from that...

The gist can be found here Gist link

I basically wanted to expaned the _createSkycon function to get the forecast using another function if the boolean (useForecast) was set to true