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

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");


(function() {
var Country = "situation.workItemType.country";

dojo.declare("situation.customization.generateSummary", null, {
getValue: function(attribute, workItem, configuration) {
var result = "Location: " + workItem.getValue(Country);
return result;
}

});
})();

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!

1

1 vote



5 answers

Permanent link
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");

var countryName = configuration.getChild(countryId).getString("name");


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.
Warning: Do not use this approach if you have saved items which are already using this enumeration. Doing so will result in corrupt work item data. Only use this approach when creating a new enumeration that has not been used before.

In the process configuration source you can modify the definitions for all enumeration literals in this way:
Old:
<literal id="country.literal.l11" name="Austria"/>

<literal id="country.literal.l30" name="South Africa"/>

New:
<literal id="country.literal.Austria" name="Austria"/>

<literal id="country.literal.South_Africa" name="South Africa"/>


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.

1 vote


Permanent link
Following on the initial question, use:
workItem.getLabel(Country);

instead of:
workItem.getValue(Country);

--
Gabriel Enriquez, IBM Rational, Tracking & Planning

1 vote


Permanent link
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? :)

0 votes


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

0 votes


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

0 votes

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

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

Question asked: May 31 '11, 10:46 a.m.

Question was seen: 8,836 times

Last updated: Jun 19 '12, 3:00 p.m.

Confirmation Cancel Confirm