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:
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!
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
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:
once you have this for each country you can use this in your script:
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:
New:
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.
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.
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.l30" name="South Africa"/>
<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.
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 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!
Thanks again Dimitar!