It's all about the answers!

Ask a question

Enumerations and Calculated Values Java script


Rob Logie (33825041) | asked Nov 06 '13, 12:23 a.m.
edited Nov 06 '13, 12:24 a.m.
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




2 answers



permanent link
Ralph Schoon (63.1k33646) | answered Nov 06 '13, 2:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. 

permanent link
Rob Logie (33825041) | answered Nov 06 '13, 9:56 p.m.
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.







Comments
Ralph Schoon commented Nov 07 '13, 2:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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