Error in Nanoflow

0
Hi,   I am using Javascript action in which I return an object of a non-persistent entity. This is the error I am getting. An error occurred while executing an action of MyFirstModule.Home_Web.actionButton3: Value [object Object] cannot be used as Nanoflow variable. Nanoflow stack: "Call JavaScript Action: MyFirstModule.JavaScript_action" in nanoflow "MyFirstModule.Nanoflow"    at http://localhost:8080/mxclientsystem/mxui/mxui.js?638551001306259967:66:234986    at be (http://localhost:8080/mxclientsystem/mxui/mxui.js?638551001306259967:24:6830)    at r (http://localhost:8080/mxclientsystem/mxui/mxui.js?638551001306259967:24:6731)    at E (http://localhost:8080/mxclientsystem/mxui/mxui.js?638551001306259967:64:5069)
asked
2 answers
1

This creates a complete object in JS

export async function JS_TEST() {
	// BEGIN USER CODE
 	let prom = new Promise((resolve, reject) => {
	 	mx.data.create({
			entity: "Administration.TestObj",
			callback: resolve,
			error: reject
		});
	});
	prom.then((obj) => {
		obj.set("Attribute","This is a test");
		console.dir(obj);
	});
	return prom;
	// END USER CODE
}

 

answered
0

Hi Harshraj,

The code snippet you provided does create a JSON object, but is not recognized as Mendix object. I'm not exactly sure how to create a non-persistent object without calling mx.data.create (which causes a server-call), so I would advise to create an object in the nanoflow before you call the JavaScript action. Then you pass this object and can use functions like  this:

parameter.set("AppName",navigator.appName)

You even don't have to return a variable then, as the object is already known in the nanoflow.

 

Thinking of this a little bit more, I would suggest to not use objects at all in your JavaScript actions, but just create 5 small actions just returning Strings. Then you can develop a nanoflow calling all the javascript actions and combine it in one object if you'd like, but anyone is free to change the domain model without breaking the Javascript without doing any coding (more stable, as no hard-coded attributes are used).

 

Hopefully this helps!

answered