Call a microflow with a list containing only 1 object from a widget ?

2
I'm currently working on a widget, which call a microflow defined as follow: <property key="myMf" type="microflow" required="false" entityProperty="myEntity" parameterIsList="true"> <caption>Event Microflow</caption> <category>Behavior</category> <description>Some description.</description> <returnType type="Void"></returnType> </property>   Within my widget, when I call this microflow with a list containing 2 or more objects, it works fine. But if my list contains only 1 object, the parameter is not sent to the microflow. Here the call: mx.data.action({ params: { applyto: "selection", actionname: this.myMf, guids: guids // This is an array of guids }, callback: function() { console.debug("OK"); }, error: function (error) { console.debug(error.description); } }, this);   I searched the forum, and it seems that it was a known issue 5 years ago, submitted with the number #9116. (cf. https://community.mendix.com/link/questions/3633) What is the status of this bug? Is it not solved, or is it the way that I call the microflow the issue?   Thanks in advance
asked
2 answers
1

Can you make sure that 'guids' is an array?

 

var guids = [];
guids.push(guid);

 

answered
1

This our workaround

 

function generateConstraintsFromArray(guids: string[]) {
    var result;
    result = "[";
    for (var i = 0; i < guids.length; i++) {
        if (i === 0) {
            result += "id=" + guids[i];
        }
        else {
            result += "or id=" + guids[i];
        }
    }
    result += "]";
    return result;
}
async function mxAction(microflow: string, guids: string[], entityType?: string): Promise<any | undefined> {
    return new Promise(resolve => {
        var params;
        if (!entityType) {//normal case
            params = {
                applyto: "selection",
                guids: guids
            };
        } else {
            if (guids.length === 1) {//workaround
                params = {
                    applyto: "selectionset",
                    sort: [["id", "asc"]],
                    xpath: "//" + entityType,
                    constraints: generateConstraintsFromArray(guids)
                };
            } else {
                params = {
                    applyto: "selection",
                    guids: guids
                };
            }
        }
        mx.ui.action(microflow, {
            context: new mendix.lib.MxContext(),
            params: params,
            progress: "modal",
            callback: function (objs: any) {
                resolve(objs);
            },
            error: function (error: any) {
                resolve(undefined);
                if (error.message) {
                    mx.ui.error(error.message);
                }
            }
        });
    });
}

 

answered