Setting an enitity with custom widget and passing it to a microflow.

0
I have a situation in my application where I want to create a custom widget which will need an entity and a microflow to be set with it. as I explored I could find that it can be done through properties.xml. But the problem I am facing is, with the custom widget one can have any entity which he prefers and the same set entity needs to be passed to the set microflow. As my microflow won’t be knowing it at runtime that what entity will be coming. Is it possible for such a scenario that at the run time, my microflow will know what entity is passed to it? Or there is some other way by which it can be achieved. Please suggest.
asked
3 answers
6

 
I'm not sure if I understand what you mean, a microflow will always know what entity is being used as a parameter, if it's the wrong one the parameter will be empty.

If you do know what kind of entities will be used as a parameters, and there are a limited number, you could try generalisations.
For instance a vehicle-customizer widget could use the entity 'car' and 'truck' both specialisations of 'vehicle'. When you make a microflow that accepts a 'vehicle' entity,it will work for both a 'car' and 'truck' object. Use the inheritance split to check which specialisation you have and execute logic accordingly.

If you have a lot of different entities that will be used as a parameter, and they are not related in a way that generalisations would make sense you could try something like this:

var entityName = mxObj.getEntity();
    var guid = mxObj.getGuid()
    if( entityName === "MyModule.Chart"){
        //execute the microflow that handles charts here
    } else if (entityName === "MyModule.User"){
        //execute the microflow that handles Users here
    } else{
        logger.error(""Unknown entity!);
    }

Let me know if this is of any use :)


 

answered
0

I suggest having a look at other widgets and how they do it. When designing your widget you should be providing configuration for the dev to select all attributes needed.

When the widget is implemented in your app you would then select the dataview entity and based on that you’d design your microflow.

If I remember this correctly, Mendix will display an error if you microflow does not expect the correct input (I.e. the same entity type that is present in your dataview).

Hope this helps

answered
0

Try following the Building Custom Widgets (Micro Learning) learning path. It explains the basics and also has an example on calling a microflow.

If you want to call a microflow based on the context object dataview/listview/template grid object surrounding the widget you do not have to specify the entity in the properties. Also, you don't need to specify the microflow entity in the widget as you just need to make sure whatever you pass through is available as a parameter in the microflow you select.

answered