Close Page action from Microflow called by custom widget not working

4
Hi, I'm currently having some issues with microflows called from custom widgets. When the microflow has a close page action, the page is not closed. Instead the browser shows an error message on the console: mxui.js?636092908209389983:29 An error occurred while handling queued requests: Cannot read property 'close' of undefined I've Checked this behaviour now with two of our own custom widgets, but also with the MicroflowTimer from the AppStore and it is the same for all. The code I'm using to call a microflow is this mx.data.action({ params: { applyto: "none", actionname: this.mfToExecute, }, store: { caller: this.mxform }, }, this); I've also tried to change that (according to the client documentation) to this mx.data.action({ params: { applyto: "none", actionname: this.mfToExecute, origin: this.mxform }, }, this); but without any other result. Has anyone else encountered such an issue?
asked
4 answers
5

This is indeed a bug, introduced in 6.8.0. Unfortunately, when introducing a new way of passing the originating page to mx.data.action we broke the old way (using the store.caller property). In 6.8.0 mx.ui.action works with both the old and the new way, but mx.data.action only works with the new way. We fixed this in 6.9.0, though we advise you to use mx.ui.action instead, which is simpler yet more advanced. Unlike mx.data.action, mx.ui.action supports passing the scope in which callback functions are executed, and provides the option to show a progress bar during the execution of the microflow.

Old way of passing the page to mx.data.action (broken in 6.8.0):

mx.data.action({
    params: { actionname: microflowName },
    store: { caller: this.mxform }
});

New way of passing the page to mx.data.action (available as of 6.8.0):

mx.data.action({
    params: { actionname: microflowName },
    origin: this.mxform
});

Old way of passing the page to mx.ui.action (available in all versions):

mx.ui.action(microflowName, { store: { caller: this.mxform } });

New way of passing the page to mx.ui.action (available as of 6.8.0):

mx.ui.action(microflowName, { origin: this.mxform });

Also see the API documentation: https://apidocs.mendix.com/6/client/mx.ui.html#.action.

answered
0

The call Microflow API currently doesn't allow you to specify which form it's on, which results in the behavior that you're experiencing: the instruction to close a form is received by the mendix JS client, but it doesn't know which form to close..

If you want to close a form from a custom widget you'll have to implement the close behavior yourself instead of relying on the close form action from Microflows.

answered
0

Faced the same issue too Fabian but I was able to overcome this using the the following function to close the form in which the widget currently resides.

this.mxform.close();

This could be implemented in a couple of ways and you can control this from a microflow for example by placing the code in the microflow callback and executing it based on the microflow's return value.

mx.data.action({
            params: {
                applyto: "none",
                actionname: this.mfToExecute,
            },
            store: {
                caller: this.mxform
            },
callback: function(bool) {
                 if(bool){
                  this.mxform.close();
                   }
                }
        }, this);

If you are thinking about having to change all custom widgets then, this could also be used in a htmlsnippet widget and by controlling when to close the form by placing visibility condition on the htmlsnippet widget. This may not be the best way to do this but I can't think of anything else till Mendix allows it back in the microflow API.

answered
0

Please note that currently I get the same browser console message (and it stops loading the page) in the following case:

A microflow that runs from the navigation (after login for example) that opens the correct page for the user. The microflow contains a Close Page action. If I remove the Close Page action it works fine, but this is needed in case a user is already logged in.

This worked 6.5.1 (we just upgraded) and I wonder if your fix in 6.9.0 will also resolve this behaviour?

Thanks

answered