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.
[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.
[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.