Access Mendix association attributes in javascript action call

Hi, i am  used javascript action  which will take a object. I can able to access the entites by using student.get(‘Name’) and able to store them in a variable and it works fine. But when i try to access the association attributes  from the below code(sample), I can able to print it, But not able to store it in a variable to access it outside of fetch() function. I am not good in JavaScript. Could someone please help me with this? Thanks in advance.    
1 answers

Declare your variable outside this fetch function, then assign it as part of the callback, which is where the alert function is called.

JS frequently uses callbacks, which are functions to be executed after the parent function has finished execution. The alert part is the function definition so all that above snippet is doing is printing a message. You just need to provide a variable to assign a value to that’s in scope. 

try something like:


var testName;

mxobj.fetch(“MyFirstModule.Student/MyFirstModule.test”, function(value) {

    testName = value.get(‘name’);



and ‘testName’ will have your attribute value stored in it