Call a nanoflow from a Javascript action - Mendix Forum

Call a nanoflow from a Javascript action

4

It would be really great to be able to call a nanoflow from a Javascript action!

The main use case for this, would be to be able to register to a Javascript event using a Javascript action. And when the event is triggered, to call the nanoflow for further action/logic.

 

asked
7 answers

@Nikolaus, true; but you don't want to hard-code the name of a microflow or pass a String variable. Ideally, you want to use a microflow/nanoflow parameter, just like you can refer to a microflow in a  Java Action activity:

Created

Nikolaus, your widget is a really good workaround!! Thanks for your idea!

Created

@Johan what do you mean by adding a Microflow as a parameter? Microflows can be called in a JS Action via the Client API (without any workarounds):

mx.data.action({
    params: {
        actionname: "MyFirstModule.PetCat"
    },
    origin: this.mxform,
    callback: function(obj) {
        // no MxObject expected
        alert("Just petted the cat a little");
    },
    error: function(error) {
        alert(error.message);
    },
    onValidation: function(validations) {
        alert("There were " + validation.length + " validation errors");
    }
});

Created

I agree, both a microflow and a nanoflow should be possible parameter types for a JavaScript action

Created

@Claire you are correct, it doesn’t work from a JavaScript action, by default. However, while playing around with it yesterday, I realized that if any widget on the page has a Nanoflow as a parameter, that Nanoflow can be called from a JavaScript action. So I created a super light-weight widget, that simply allows you to select a Nanoflow as a parameter. It doesn’t execute the Nanoflow – it simply makes it accessible via Client API. You can find the widget here: https://appstore.home.mendix.com/link/app/111132/ 

 

That should work until Mendix addresses this idea.

Created

@Nikolaus, It’s possible from a widget, but not from a Javascript action.

Created

Isn’t this already possible, using the Client API: 

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);
    }
});

Taken from the Mendix 7 API Documentation https://apidocs.mendix.com/7/client/mx.data.html

Created