It's all about the answers!

Ask a question

Javascript. Can't get value from an enumeration. "NaN"


Daniel Flores Montanez (19813) | asked Jun 08 '16, 11:16 a.m.
 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



permanent link
anup Gaur (1392144) | answered Jun 08 '16, 12:42 p.m.
 Hi Daniel,

Can you try this URL, it has examples which may help you.

https://jazz.net/wiki/bin/view/Main/AttributeCustomizationExamples

Best of lucks.

Comments
Daniel Flores Montanez commented Jun 08 '16, 3:55 p.m.

I've looked at that link and it just says that you should use the id, which I am. 


I'm trying to simply display what enumeration the attribute is currently using so :

var priority= parseFloat(workItem.getValue("com.ibm.team.workitem.attribute.priority")); return priority.toString(); 


but this is giving me no results.
I'ved used the ids for the enumerations as well and nothing.


anup Gaur commented Jun 08 '16, 4:17 p.m. | edited Jun 08 '16, 4:18 p.m.
 Any reason why you are trying to parse it to float? and then convert again to String??
Sorry If I am missing something here.
Try the line below

var mypriority = workItem.getValue(WorkItemAttributes.PRIORITY);

also you can try the URL below for Built-in attributes attribute internal name / id.




Daniel Flores Montanez commented Jun 09 '16, 10:17 a.m.

the parsefloat part is extra, but yes even when you do 

var mypriority = workItem.getValue(WorkItemAttributes.PRIORITY); 
return mypriority;
or 
return mypriority.toString();
I still get this NaN value. as if the value didn't exist, when it clearly does.
I just checked your link got very excited when I saw there was a getLabel function but still nothing. 
The reason I'm doing the immediate "getValue then return" is for testing purposes so later I can do
if(mypriority == "2"){
//capture date here... I already got this part working
}
but that can never happen because my priority will never equal 2 because my priority is receiving no value. I've tried every id possible..


Donald Nong commented Jun 09 '16, 9:29 p.m.

If you still get NaN, there is something wrong in your code, as NaN basically means "not a number" and you must be parsing something to a number explicitly or implicitly. Note that for the Priority attribute, both its value and label are strings, not numbers. For example, value - "priority.literal.l02", and label - "Low".


permanent link
anup Gaur (1392144) | answered Jun 09 '16, 1:54 p.m.
edited Jun 09 '16, 1:59 p.m.
 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

Your answer


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.