Javascript. Can't get value from an enumeration. "NaN"
![]()
I'm trying to getvalue() of an enumeration and it's simply not working. This should be easy enough to do.Right now I'm simply trying to get it then display it so that I know what the values are so i can make make conditions later on.
So here's is the attribute id for the attribute Priority. Priority's type is "Priority (Enumeration)"
com.ibm.team.workitem.attribute.priority
Here's the source for "Priority (Enumeration)
</enumeration>
<enumeration attributeTypeId="priority" name="Priority">
<literal default="true" externalValue="" icon="processattachment:/enumeration/unassigned.gif" id="priority.literal.l01" name="Unassigned" null="true"/>
<literal externalValue="" icon="processattachment:/enumeration/low.gif" id="priority.literal.l02" name="Low"/>
<literal externalValue="" icon="processattachment:/enumeration/medium.gif" id="priority.literal.l07" name="Medium"/>
<literal externalValue="" icon="processattachment:/enumeration/high.gif" id="priority.literal.l11" name="High"/>
</enumeration>
so the Id's are:
"priority"
"priority.literal.l01"
"priority.literal.l07"
"priority.literal.l11"
Now my script is very simple. I'm just trying to get the value and redisplay it.
dojo.provide("com.example.resulttest");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { dojo.declare("com.example.resulttest", null, { getValue: function(attribute, workItem, configuration) { try { var priority= parseFloat(workItem.getValue("com.ibm.team.workitem.attribute.priority")); var RES; RES = priority; return RES.toString(); }
}
});
})();
I've created a new attribute set to this scriptwith this script and set my dependencies to the priority attribute.
I've tried setting the id to each of the enumeration id's
I've tested it as a string, decimal and html attribute.
String returns "NaN" and Decimal returns "0"
What is happening here?
Has anyone tried this and are there any pointers??
|
2 answers
![]()
Here is a working example,
hope this helps.
Steps that I followed:
1) I created a new attribute.
2) made this attribute dependent on the Priority attribute.
3) Create a new attribute customization script for calculated value part of my attribute.
4) made my attribute property have the calculated value script.
5) Make sure Enable Process Attachent scripts is enabled in CCM/admin in advanced properties.
Here is the actual script below.
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.provide("org.swp.akg.MyPriority");
(function() {
dojo.declare("org.swp.akg.MyPriority", null, {
getValue: function(attribute, workItem, configuration) {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes
var mystr = workItem.getValue(WorkItemAttributes.PRIORITY);
console.log("This is mystr : " + mystr);
return mystr;
}
});
})();
Note: the NaN error can come if you have a wrong parse method called
|