It's all about the answers!

Ask a question

How to set value of custom attribute type Enumeration?


Kruttika Pendharkar (2174) | asked Nov 17 '11, 6:57 a.m.
Hi,

Can anybody tell me how can we set value for custom attribute of type Enumeration?
When trying to set a string value getting exception as:
"java.lang.String incompatible with com.ibm.team.workitem.common.model.Identifier"

Any suggestion or piece of code would be a great help.

Thanks.

Accepted answer


permanent link
Ralph Schoon (57.1k23642) | answered Sep 28 '19, 9:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Pretty much any attribute type is explained there. Also see https://rsjazz.wordpress.com/2019/07/03/work-item-command-line-5-0/ and the attached source code that reads and writes almost all attribute types as well.
Ralph Schoon selected this answer as the correct answer

4 other answers



permanent link
Sterling Bates (2311612) | answered Nov 21 '11, 12:16 p.m.
edited Sep 27 '19, 2:15 p.m. by David Lafreniere (4.5k7)
Any help?
I have seen one article stating how to set value for Filed against.
but how to deal with custom enumeration attributes?
Any body?


The key for me was discovering that enum values all have an underlying ID. So if you have an enum named "version" with values "1.0.0.0" and "1.1.0.0", each of those two values will have an ID and that ID is what gets stored with the work item.

I do something like this to get at enum attributes:

String enumAttributeName = "version";

String value = "1.0.0.0";
String id = null;
IWorkItemClient client = (IWorkItemClient)repo.getClientLibrary(IWorkItemClient.class);
IAttribute attribute = workItemClient.findAttribute(areaHandle, enumAttributeName, null);
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>) workItemClient.resolveEnumeration(attribute, null);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals)
if (literal.getName().equalsIgnoreCase(value))
id = literal.getIdentifier2().getStringIdentifier();


permanent link
Kruttika Pendharkar (2174) | answered Nov 18 '11, 4:16 a.m.
Any help?
I have seen one article stating how to set value for Filed against.
but how to deal with custom enumeration attributes?
Any body?

permanent link
sam detweiler (12.4k6179201) | answered Nov 18 '11, 10:39 a.m.
Any help?
I have seen one article stating how to set value for Filed against.
but how to deal with custom enumeration attributes?
Any body?


well you have to create the value object(Identifier) first, then setValue(attribute, object) should work. This is an OO system

how do you create an Identifier? I would look up its constructors
in Eclipse, this is click on the classname, and select 'Open Declaration' from the popup menu (or hit f3 if u can remember the keystroke mnemonics)

Sam

permanent link
Ryan Golbeck (211) | answered Dec 14 '11, 4:20 p.m.
Is there anyway to get an IEnumeration directly without having an attribute of that enumeration type (Not calling resolveEnumeration) in the Java API?

Basically, what I have is an attribute on a work item that should be a multi select attribute. To set this up I created an attribute of type string, and added a presentation editor that attaches an enumeration to the custom attribute.

When multiple values of the enumeration are selected, the string value of the custom work item is something like &quot;test.multiselect.enumeration.l1,test.multiselect.enumeration.l2&quot; and I need a way of first knowing that this custom attribute of type string is actually a multi select, and second translating the values of the enumeration literals to the display names.

Thanks for any help,
-ryan

Your answer


Register or to post your answer.