Enumerations and Calculated Values Java script
Hi
I have a enumeration in a work item defined as this:
However, when I execute this call in the Calculated value script:
Also, if I try and use "workitem.getLabel" to get the label value for the enumeration, for example,
It throws an exception. Any ideas what I could be doing wrong ?
Thanks in advance
Rob
I have a enumeration in a work item defined as this:
<enumeration attributeTypeId="ConsultingTimesheet.ConsultedDepartmentorArea2" name="ConsultingTimesheet.ConsultedDepartmentorArea2">This enumeration is then used in a work item attribute with id: enumeration.ConsultingTimesheet.ConsultedDepartmentorArea
<literal default="true" id="ConsultingTimesheet.ConsultedDepartmentorArea2.literal.l2" name="Consulted Department 1"/></enumeration>
<literal id="ConsultingTimesheet.ConsultedDepartmentorArea2.literal.l4" name="Consulted Department 2"/>
However, when I execute this call in the Calculated value script:
var summary3 = workItem.getValue("enumeration.ConsultingTimesheet.ConsultedDepartmentorArea");It is always returning the default value
console.log("Summary3: " + summary3);
ConsultingTimesheet.ConsultedDepartmentorArea2.literal.l2In 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
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.
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.
Hi Ralph,
Thanks for your comments.
What I do find confusing is this comment in the workshop
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
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.