Programatically finding a literal displayed name from its ID
![]()
Hi,
I have a question about calculated values configuration. To simplify, I have an enumeration-type attribute "Country" containing various names of countries, and I would like to automatically copy its content to another string-type attribute. My problem is, that what I am getting back is the id of the literal, not its displayed name (e.g. "country.literal.l1" instead of "Austria") Here is the code that I have: dojo.provide("situation.customization.generateSummary"); How can I get the displayed name corresponding to that particular literal id? After looking at various articles and threads here, I've also tried to play around with configurations but haven't been successful either... Thanks in advance for your help! |
5 answers
![]()
Hi Thibault,
I would recommend that you read this new Wiki about attribute customization: https://jazz.net/wiki/bin/view/Main/AttributeCustomization. It contains details about configuring a script with additional parameters in the project specification. The current API we provide for working with enumerations is very limited and there is no direct way to get a literal's name from its id. There are two indirect ways of achieving what you want, but they have drawbacks: 1. Configure the calculated value provider in the process specification by including a mapping between a country id and name. This means that for each country you need to add a new entry like this to the configuration: <country.literal.l1 name="Austria" /> once you have this for each country you can use this in your script: var countryId = workItem.getValue("situation.workItemType.country"); Advantages: It works without changing the definition of an existing enumeration. Disadvantages: You need to maintain a duplicate list of countries. 2. Manually encode the country name in the literal id of a country. In the process configuration source you can modify the definitions for all enumeration literals in this way: <literal id="country.literal.l11" name="Austria"/> <literal id="country.literal.Austria" name="Austria"/> Then you can parse the literal within Javascript and extract the country name from it. Literal ids should not contain bank space characters so you will need to encode them somehow, the example above uses underscore. Advantages: There is no duplication of country literal data Disadvantages: Can not use this with existing enumerations. If a new country is added later on, the corresponding literal id will need to be adjusted. If a country's name changes you can not change its corresponding literal id as this will corrupt existing entries. Both of these approaches are not very convenient, but I would recommend the first one as it is safer to use. |
![]()
Gabriel Enriquez (346●3)
| answered Jun 19 '12, 2:59 p.m.
JAZZ DEVELOPER edited Jun 19 '12, 3:00 p.m.
Following on the initial question, use:
instead of:
-- Gabriel Enriquez, IBM Rational, Tracking & Planning |
![]()
Thanks a lot Dimitar, even if not perfect, workaround 1 is indeed the best, and works like a charm. I don't think the country list will change that often... :)
Do you think I should submit an Enhancement against RTC to add an API that would provide te enumaration's displayed name? :) |
![]()
Hi Thibault,
I am glad the workaround is suitable for your case. I am part of the RTC dev team and we are aware that the current API we provide is very limited. In general we want to improve this but do not have any specific plans yet. It might help to submit an Enhancement request and briefly outline your use case. |
![]()
I have created Enhancement 168602 (https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=168602) for this.
Thanks again Dimitar! Comments Has this API been improved IN RTC 4.0? Mark According to the Enhancement record, it should be implemented in v4 but Dev would be the ones to confirm. |
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.