It's all about the answers!

Ask a question

Programatically finding a literal displayed name from its ID


1
1
Thibault Leclercq (9011013) | asked May 31 '11, 10:46 a.m.
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!

5 answers



permanent link
Thibault Leclercq (9011013) | answered Jun 09 '11, 6:50 a.m.

Comments
Mark Williamson commented Jun 19 '12, 9:11 a.m.

Has this API been improved IN RTC 4.0?

Mark


Thibault Leclercq commented Jun 19 '12, 9:16 a.m.

According to the Enhancement record, it should be implemented in v4 but Dev would be the ones to confirm.


permanent link
Dimitar Asenov (211) | answered Jun 09 '11, 6:28 a.m.
JAZZ DEVELOPER
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.

permanent link
Thibault Leclercq (9011013) | answered Jun 09 '11, 6:08 a.m.
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? :)

permanent link
Gabriel Enriquez (3463) | answered Jun 19 '12, 2:59 p.m.
JAZZ DEVELOPER
edited Jun 19 '12, 3:00 p.m.
Following on the initial question, use:
workItem.getLabel(Country);

instead of:
workItem.getValue(Country);

--
Gabriel Enriquez, IBM Rational, Tracking & Planning

permanent link
Dimitar Asenov (211) | answered Jun 01 '11, 4:56 a.m.
JAZZ DEVELOPER
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.

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.