DNG RM Extension Javascript variable scope
I am using javascript to access the RM Extensions API and this is one of my functions
(ref is an artifact reference and attrName is the name of an attribute)
function getAttrVal(ref, attrName)
{
var result = "null"
RM.Data.getAttributes(ref, attrName, function(result)
{
var attributes = result.data;
attributes.forEach(function(attr)
{
var attrVal = attr.values[attrName];
println("Check " + attrVal) // here it is printing 'Check 5' which is correct since attrVal should equal '5'
result = attrVal;
});
});
return result; // but here it returns the value 'null'
}
How do I get the variable 'result' to be 5 when it is returned.
It seems to be a variable scope issue.
I am just feeling my way with this javascript stuff. It is a foreign language compared to DXL.