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 test.name attribute value stored in it