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

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?? 

0 votes



2 answers

Permanent link
 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.

0 votes

Comments

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.

 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.



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..

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
 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

0 votes

Your answer

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,121
× 457
× 152
× 4

Question asked: Jun 08 '16, 11:16 a.m.

Question was seen: 4,586 times

Last updated: Jun 09 '16, 9:29 p.m.

Confirmation Cancel Confirm