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

Enumerations and Calculated Values Java script

Hi
I have a enumeration in a work item defined as this:
 <enumeration attributeTypeId="ConsultingTimesheet.ConsultedDepartmentorArea2" name="ConsultingTimesheet.ConsultedDepartmentorArea2">                   
<literal default="true" id="ConsultingTimesheet.ConsultedDepartmentorArea2.literal.l2" name="Consulted Department 1"/>                   
<literal id="ConsultingTimesheet.ConsultedDepartmentorArea2.literal.l4" name="Consulted Department 2"/>               
</enumeration>
This enumeration is then used in a work item attribute with id:  enumeration.ConsultingTimesheet.ConsultedDepartmentorArea

However, when I execute this call in the Calculated value script:
var summary3 = workItem.getValue("enumeration.ConsultingTimesheet.ConsultedDepartmentorArea");
console.log("Summary3:  " + summary3);
It is always returning the default value
ConsultingTimesheet.ConsultedDepartmentorArea2.literal.l2
In the log file, no matter what value I select in the enumeration in the work item I have created.  So it seems to always be returning the default value for the enumeration rather than the selected value.  Does any one know what I may be doing wrong in the script ?

Also, if I try and use "workitem.getLabel" to get the label value for the enumeration, for example,
var summary3 = workItem.getLabel("ConsultingTimesheet.ConsultedDepartmentorArea2.literal.l2");


It throws an exception.  Any ideas what I could be doing wrong ?

Thanks in advance

Rob




0 votes



2 answers

Permanent link
Hi Rob,

you can not get the label from an enumeration literal as you do above. workItem.getLabel(attributeID) only works for attribute ID's and gets the label of the value of said attribute. I have been able to get the literals and labels of enumerations. I have described this in Lab 5 of https://jazz.net/library/article/1093 and I would suggest you have a look at the 'Spy' script and the lab in total. The examples should help you to understand the basics and there is a section explaining the limitations of the JavaScript API.

Another thought is, if you create a calculated value script, for which attribute is that script above configured? If it is for enumeration.ConsultingTimesheet.ConsultedDepartmentorArea then, I think it would always return the default. If you want to calculate the value of an attribute from its own value, there are issues to be expected. In general calculated attributes should be read only and calculated from other attribute values. 

0 votes


Permanent link
Hi Ralph,
Thanks for your comments.
What  I do find confusing is this comment in the workshop

Enumeration Types: It is possible to access enumeration types. The operation getValue() returns theliteral ID of the Enumeration Literal. The operation getLabel() allows to access the Enumeration Literaldisplay value. To set an enumeration value use the Literal ID. See Working with Enumerations for moreinformation about using Enumerations in scripts.






0 votes

Comments

This talks about the values of enumeration type attributes. You can get the label (getLabel) or the literal (getValue) of the attribute's value. I agree it could be clearer. Unfortunately I am not a native English speaker/writer and some stuff is not picked up in the reviews - maybe because the reviewer know too much. I will make a note to try to address that in an overhaul.

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
× 10,938

Question asked: Nov 06 '13, 12:23 a.m.

Question was seen: 5,884 times

Last updated: Nov 07 '13, 2:08 a.m.

Confirmation Cancel Confirm