It's all about the answers!

Ask a question

Customizing calculated value but get NaN as result


Daniel Torres (749) | asked Aug 27 '18, 5:21 a.m.
Hi, I'm trying to get a calculated value on a custom attribute, this attribute is an integer type, and is also integer kind on presentation. I want it to count each time it reaches to an specific state. I'm using the following script:

dojo.provide("counterString");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("counterString", null, {
    getValue: function(attributeId, workItem, configuration) {
    var counter = parseInt(workItem.getValue("counterString"));
    console.log("Counter: " + counter + "\n\n");
        var stat = workItem.getValue(WorkItemAttributes.STATE);
        console.log(counter);
        console.log(stat);
        if(stat === "s5")
            {  
                console.log("Actual value:" + counter);
                counter = counter+1;
                console.log("New Value:" + counter);
            }
                return parseInt(counter);
    }
});
})();

The state condition works fine, but not for the counter, when I check my log it says "Counter: NaN".
What should I change on my script?

One answer



permanent link
Daniel Torres (749) | answered Aug 27 '18, 2:44 p.m.
I solve this on my own. I hope this helps anyone who had a similar problem.

dojo.provide("counterString");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
var counter = 0;
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("counterString", null, {
    getValue: function(attributeId, workItem, configuration) {
    console.log("Counter: " + counter + "\n\n");
        var stat = workItem.getValue(WorkItemAttributes.STATE);
        console.log(counter);
        console.log(stat);
        if(stat === "s5")
            {  
                console.log("Actual value:" + counter);
                counter= counter+1;
                console.log("New value" + counter);
            }
                return parseInt(counter);
    }
});
})();

Comments
Daniel Torres commented Aug 27 '18, 7:17 p.m.
I got an issue, everytime I refresh the webpage, the counter increases on 3, and when I check the log it shows like the WI was saved 3 times. why is that if I'm only refreshing the webpage? Any tip please???

Thanks,

Your answer


Register or to post your answer.