Multiple context objects available in widget

The mxui/widget/_WidgetBase.update(obj, callback) ( function only supplies the widget with one context object. If I then want to call for example an "onChange" microflow I can only pass this one context object.  If the widget is placed in multiple dataviews I would also like to be able to pass all the context objects to the microflow.  When using a default input control from Mendix you have access to 2 context objects in your "onChange" microflows. Could this functionality be added to the WidgetBase or is there already a way to do this?
5 answers

Hi Martin,
Not exactly ideal, but you can get your parent widget in javascript by calling something like

Then you could retrieve that widgets contextObject. Its just an idea



Hi Martin, 

I like Andrej's answer, never knew you could do that .

Another option, depending on the complexity of your widget is to use references. Create a  main non persistable DummyContext in which the widget is placed then setting references to other entities to which you need access from your widget.

The Drag Drop Support widget is a great example. 



Hi Martijn,

In a widget, you can also access the stored "context path" from your current context object back to the highest-level context on the page:

// where `this` is the widget instance

  "TestSuite.NextLevelContextEntity": "{guid}",
  "TestSuite.CurrentContextEntity": "{guid}"

This is especially useful if you're just trying to get the guid of the next level up (likely associated) object. Keep in mind though, that you can probably just do this retrieve in the microflow as well.


Hi Martijn,

It is not possible to select a microflow with 2 parameters for a custom widget. As workaround you could use a string parameter.

Calling a microflow, you could use the the parameter and context to provide the 2 objects{
    params: {
        applyto: "selection"
        actionname: "MyFirstModule.GetFavoriteFood",
        guids: [ "281530811285515"]
    origin: this.mxform,
    context: this.mxcontext,
    callback: function(obj) {},
    error: function(error) { }

in case you dont want use the context of the form but an other object, you can create a new context

var c = new mendix/lib/MxContext();
context.setContext("MyFirstModule.Entity", "12345");




The answers here provide some workaround but we can all agree they are just workarounds.


If you want to see this implemented in the platform itself upvote the idea: