Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.


0 votes


Be the first one to answer this question!

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 6,122

Question asked: Aug 16 '18, 1:51 p.m.

Question was seen: 1,498 times

Last updated: Aug 16 '18, 1:51 p.m.

Confirmation Cancel Confirm