Microflow not receiving multiple parameters from JS

0
When I try to call a Microflow using the mx.data.action API call with 2 guids, my microflow says that both of the objects it receives are empty. This happens regardless of the order I supply them in. See below. // Assume that 12345678901234567 is of the first parameter and 23456789012345678 is the 2nd parameter in the Microflow. mx.data.action({ params: { applyto: "selection", actionname: "MyFirstModule.DS_Test_Multiple_Objects", guids: ["12345678901234567", "23456789012345678"] }, callback: function(obj) { console.log(obj); }, error: function(error) { alert(error.message); } }); Found field from view: <empty> and cell <empty>. Exists? no However, when I only supply 1 guid, the Microflow receives this single object. Setting the first parameter only: mx.data.action({ params: { applyto: "selection", actionname: "MyFirstModule.DS_Test_Multiple_Objects", guids: ["12345678901234567"] }, callback: function(obj) { // expect single MxObject console.log(obj); }, error: function(error) { alert(error.message); } }); Found field from view: set. and cell <empty>. Exists? no Setting the second parameter only: mx.data.action({ params: { applyto: "selection", actionname: "MyFirstModule.DS_Test_Multiple_Objects", guids: ["23456789012345678"] }, callback: function(obj) { // expect single MxObject console.log(obj); }, error: function(error) { alert(error.message); } }); Found field from view: <empty> and cell set.. Exists? no Why is that, and how can I fix it? I’m following the example from https://apidocs.mendix.com/7/client/mx.data.html with multiple guids. The two objects I’m passing are of different types.   Thank you in advance.
asked
3 answers
4

Hi Andreas, 

as far as I know, it is not possible to pass two or more objects to a microflow via the JavaScript API which are of different types. You can only pass multiple GUIDs of the same type, which results in a list of objects (same type) as the parameter. 

You could use something like a wrapper object, which is associated to the two objects you want to pass as parameters and in the microflow you retrieve them via those associations. 

answered
3

After a little further research, it appears that using mx.onlineData.executeMicroflow allows for calling microflows with multiple objects of different types.

The mx.onlineData API namespace doesn't appear to be documented yet, so this is taken from a trial-and-error approach.

mx.onlineData.executeMicroflow("MyFirstModule.DS_Test_Multiple_Objects", {
  "FirstParameter":{
    "guid":"12345678901234567"
  },
  "SecondParameter":{
    "guid":"23456789012345678"
  }
}).then(console.log);

 

answered
0

2024 update

 

  mx.data.action allows for at most 1 non-list object of each entity type  plust one list. This limitation comes from the JSON format of the  "executeaction" action: all the non-list parameters are passed in the  "context" array of guids and the parameter names are just unsupported.  If you pass more than one GUID of the same entity type then on the server side  one of them will be mapped to all parameters of this type and the others will  be discarded.

  The more advanced "runtimeOperation" action used by buttons and nanoflows  allows passing the parameter names and values, but the JS API to call it is  inaccessible from user scripts: the "runtimeOperation" action JSON is created  by the inaccessible class OnlineData. The common function used for both  "runtimeOperation" and "executeaction" is also inaccessible.

  The public property mx.onlineData was removed from Mendix somewhere in 2020.

  Finally, there's no way to directly call "runtimeOperation" using  window.fetch() because the value of X-Csrf-Token received during login is also  inaccessible.

  Resolution: you probably can wrap window.fetch() and convert "executeaction"  JSON into "runtimeOperation" JSON when necessary. The JSON format of  "runtimeOperation" can be guessed by playing with the inaccessible  OnlineData.executeMicroflow(). Currently, an istance of OnlineData can only be  obtained by using the debugger.

  The other parts of the JSON like "objects" and "changes" can be copied from  "executeaction": mx.data.action does a good job filling them for you.

 

answered