It's all about the answers!

Ask a question

DNG RM Extension Javascript variable scope


Sean F (1.3k252162) | asked Aug 16 '18, 1:51 p.m.

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.


Be the first one to answer this question!


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.