It's all about the answers!

Ask a question

setValue in custom enumeration


carlo gneo (9694) | asked Jul 06 '09, 10:39 a.m.
How can I set a value in a custom enumeration?

I use this code for example to set the Priority

IAttribute priority = service.findAttribute(projectArea,IWorkItem.PRIORITY_PROPERTY, monitor);

IEnumeration<IPriority> resolveEnumerationPriority = (IEnumeration<IPriority>) workItemCommon.resolveEnumeration(priority, monitor);
List priorities = resolveEnumerationPriority.getEnumerationLiterals();
IPriority priorityLiteral = (IPriority) priorities.get(2);
workItem.setValue(priority, priorityLiteral.getIdentifier2());


But I don't know how to set the value in custom enumeration.
Thanks in advance.

One answer



permanent link
Michael Scharf (781) | answered Jul 07 '09, 3:51 a.m.
cargne80 wrote:
How can I set a value in a custom enumeration?

I use this code for example to set the Priority

IAttribute priority =
service.findAttribute(projectArea,IWorkItem.PRIORITY_PROPERTY,
monitor);
IEnumeration<IPriority> resolveEnumerationPriority =
(IEnumeration<IPriority>)
workItemCommon.resolveEnumeration(priority, monitor);
List priorities =
resolveEnumerationPriority.getEnumerationLiterals();
IPriority priorityLiteral = (IPriority)
priorities.get(2);
workItem.setValue(priority,
priorityLiteral.getIdentifier2());

But I don't know how to set the value in custom enumeration.
Thanks in advance.



it works basically the same as in the example above, except that you need to load your custom attribute by ID, then use ILiteral instead of IPriority

IAttribute myAttribute= workItemCommon.findAttribute(projectArea, "myCustomAttributeId", monitor);
IEnumeration<ILiteral> enumeration= (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(myAttribute, monitor);
List<ILiteral> literals= enumeration.getEnumerationLiterals();
ILiteral literal = literals.get(2);
workItem.setValue(myAttribute, literal.getIdentifier2());


--
MikeS
Jazz Agile Planning team

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.