[SOLVED] How can i return a javascript action object for a nanoflow ?

1
Hey guys,  I am trying to return a javascript action object, but as an example, I will describe something basic to improve understanding. 1– In the image below, I create an object normally and try to return it    2- In the image below I define the return type as an object and the entity     3- My client entity has the same attributes as my action object   4- In this part, I created a nanoflow, pulled the javascript action and then put an activity to print the attributes of this object     5- I try to execute this nanoflow from a button, but I get this error   thanks in advance
asked
3 answers
1

You have to create the Mendix object while you are in the javascript. Do this using mx.data.create like they show in https://docs.mendix.com/howto/extensibility/write-javascript-github.

Or a better example: https://gist.github.com/tieniber/aafebadcd2f14f2e181267ef45b21128

 

Got this far:

// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import { Big } from "big.js";

// BEGIN EXTRA CODE
async function createMxObj(entity) {
	return new Promise(function(resolve,reject) {
		mx.data.create({
			entity: entity,
			callback: function(obj) {
				resolve(obj);
			},
			error: function(e) {
				reject("Could not create object:", e);
			}
		}
		);
	});
}
// END EXTRA CODE

/**
 * @returns {Promise.<MxObject>}
 */
export async function TestNanoflow107015() {
	// BEGIN USER CODE
	const obj = await createMxObj("Service.Client");
	obj.set("name", "Johnes");
	obj.set("age", "23");
	obj.set("country", "Brazil");
	return obj;
	// END USER CODE
}

but obj.set is not yet setting the values.

answered
1

[SOLVED]

I was trying to return an object of type address, from the Goolge Maps Geocode API, I will get a Latitude and Longitude from the user via [GetCurrentLocation] from Nanoflow Commons (marketplace module), and return an address "near" their current location.

There are still some problems to be solved, but overall that's it, just implementing on the project now.

I don't know if there is an easier way to do this, but this is what I found.

 

answered
1

[CORRECTION]

This is the right way to do it, the previous way was causing some bugs during the execution.

 

If you prefer you can create another constant to store another part of the address and make a loop to perform the assignment, this way it is less verbose.

 

answered