How to read the value of an attribute of a workitem with Plain Java API?
The workitem has some attributes: Type, Tags, Task Completion, Severity, Status... I need from these the value of Status (smallstring) . I get the identifier of the Status it is internalState.
workItem = copy.getWorkItem();
com.ibm.team.workitem.common.model.IAttribute status = workItemClient
.findAttribute(workItem.getProjectArea(),
"internalState", null);
System.out.print(workItem.getValue(status));
I don't know why I get this Exception:
java.lang.IllegalStateException: Attempting to get unset feature: Creator at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.getCreator(WorkItemImpl.java:1362) at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.eGet(WorkItemImpl.java:2338) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1021) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1013) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1008) at com.ibm.team.workitem.common.internal.PropertyUtil.get(PropertyUtil.java:105) at com.ibm.team.workitem.common.internal.PropertyUtil.get(PropertyUtil.java:109) at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.getValue(WorkItemImpl.java:2897) at Sample.analyzeItem(Sample.java:146) at Sample.analyzeReference(Sample.java:103) at Sample.run(Sample.java:91) at Sample.main(Sample.java:38)
The exception thrown when i call the getValue() function. If somebody know the problem please show some example code!
Thanks your help!!
Accepted answer
Hi,
please find sample code and considerations at https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
I assume your work item was resolved using a profile that does not include the attribute. Compare this entry:
https://jazz.net/forum/questions/21082/problem-in-retrieving-creator-and-creation-date-attributes
If that is not solving the issue you are possibly getting a work item which does not have the attribute set yet. Please consider using the
if (workItem.hasCustomAttribute(customString)){ Object value = workItem.getValue(customString); if (value instanceof String) { String attributeValue = (String) value; // do something with the value } } code fragment from the article.
If this answers your question please mark the answer as accepted.
- Arne