Java Script access assocition object attributes

0
Hi, i am  used javascript action  which will take a object. I can able to access the entites by using student.get(‘Name’). But how to access the association attributes, like i want to access name (under the test entity). I tried using student.get(‘MyFirstModule.Student_test’), But it returns a 17 digit number, but not the data. Can someone please help me in accessing those. Thanks in advance.     OCT 2nd update:- i tried the code provided by Johan. It working fine. But i want to store it in a variable to use it further in the code. But when i try to save it in a variable and try to print it, it is not showing the actual value, But rather than showing [object promise]. i have included the screenshot below.    
asked
1 answers
1

Hi,

Apart from the question why you would want this (you can do most things in microflow/nanoflows?)

The documented way is as follows (https://apidocs.rnd.mendix.com/10/client/mendix_lib_MxObject.html):

export async function JS_Test(parameter) {
	// BEGIN USER CODE
	parameter.fetch("Module.TestEntity_MendixAccount/Module.MendixAccount", function(value) {
    	alert("Name is " + value.get("FullName"));
	});
	// END USER CODE
}

Good luck!

 

__

Update 2 Oct:

If you want to return it back to the nanoflow like this, you need to make use of the Promise. Updated code below.

export async function JS_Test(parameter) {
	// BEGIN USER CODE
	return new Promise((resolve, reject) => {
		parameter.fetch("Module.TestEntity_MendixAccount/Module.MendixAccount", function(value) {
			const fullName = value.get("FullName");
			alert("Name of person's friend is " + fullName);
			// Resolve the Promise with the result
			resolve(fullName);
		});
	});
	// END USER CODE
}
answered