Multiple context objects available in widget

1
The mxui/widget/_WidgetBase.update(obj, callback) (https://apidocs.mendix.com/7/client/mxui_widget__WidgetBase.html) 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?
asked
5 answers
3

Hi Martin,
Not exactly ideal, but you can get your parent widget in javascript by calling something like
dijit.getEnclosingWidget(widget.domNode.parentNode);

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

-Andrej

answered
1

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. 

 

answered
1

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

this.mxcontext._contextStore;
/*
{
  "TestSuite.TopLevelContextEntity":"{guid}",
  "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.

answered
0

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

mx.data.action({
    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");

Sheers,

Andries

answered
0

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:
https://forum.mendix.com/link/ideas/766

answered