Call a Nanoflow from Javascript action

1
Hi All, I am trying to call a nanoflow from javascript action, modeler version used is 8.6.2 I tried using this ,callNanoflow(params) mx.data.callNanoflow({ nanoflow: this.propertyWithNanoflow, origin: this.mxform, context: this.mxcontext, callback: function(result) { alert("Nanoflow completed with result " + result); }, error: function(error) { alert(error.message); } }); from https://apidocs.rnd.mendix.com/8/client/mx.data.html. without context and origin,  I get undefined error  Nanoflow call currently looks like this, mx.data.callNanoflow({ nanoflow: "Info.TestNanoflow", //not sure how to get and add context and origin here callback: function(result) { alert("Nanoflow completed with result " + result); }, error: function(error) { alert(error.message); } });                            I am not sure what the values of context and origin must be, i do not have ‘this’ available. Also how do I pass a parameter to this nanoflow call, I have an entity which i need to pass as a parameter to this nanoflow call   Thanks in advance,        
asked
4 answers
2

Hi Divya,
you can check this document it’s so helpful: https://apidocs.rnd.mendix.com/8/client/mx.data.html 

best regards,
Abdelrahman Abu Al-Ata

answered
1

I'm afraid I've no complete answer for you, I struggle also with it.

The reason for the undefined message, is that the nanoflow should have been declared first.

You can however provide the nanoflow as a parameter to the JS-action.

Same applies for the context.

So you get something like this:

    return new Promise(function (resolve, reject) {
        mx.data.callNanoflow({
            nanoflow: testNanoflow, // parameter JS-action
            context: testEntity, // parameter JS-action
            origin: page, // ??????
            callback: function(result) {
                alert("Nanoflow completed with result " + result);
            },
            error: function(error) {
                alert(error.message);
            }
       });

Leaves the origin I guess, perhaps somebody else can provide some final answer here.

answered
0

Hi Divya,

Call I microflow could be really easy. with the Nanoflow parameter (not sure what version it was introduced)

https://docs.mendix.com/refguide/javascript-actions#2-2-2-type

Before it was a bit harder, to get the nanoflow exported, it required a helper widget

https://appstore.home.mendix.com/link/app/111132/

Alternatively, you could also return the date from the the JS action and call a sub nanoflow (now supported) with the data of your custom action.

Cheers, Andries

 

answered
0

For those who arrive here wondering how to pass multiple parameters to the nanoflow via JS, following is a snippet:
 

export async function JS_ExecuteSyncInBackground(nanoflow, obj1, obj2, obj3) {

    // BEGIN USER CODE

    nanoflow({ParameterName1: obj1, ParameterName2: obj1, ParameterName3: obj3});

    // END USER CODE

}

answered