How can i update the status and priority and severity and iteration of a workitem?
I am able to set the summary and description. I need to set the priority bt it gives me:
ERRORS:
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at com.ibm.team.workitem.common.internal.EnumerationManager.getEnumerationAttributeType(EnumerationManager.java:129)
at com.ibm.team.workitem.common.internal.EnumerationManager.resolve(EnumerationManager.java:70)
at com.ibm.team.workitem.common.internal.WorkItemCommon.resolveEnumeration(WorkItemCommon.java:538)
at login.WorkitemUpdate.IterationRecursiveLiteral(WorkitemUpdate.java:223)
at login.WorkitemUpdate.IterationRecursiveLiteral(WorkitemUpdate.java:148)
at login.WorkitemUpdate.getIterationLiteral(WorkitemUpdate.java:112)
at login.Login.main(Login.java:121)
ALso i cannot typecast it to literal to i attribute type.
please help me
if(workItem.getId()==xxxxx){
List allAttributeHandles = workItemClient.findAttributes(area, null);
for (Iterator iterator = allAttributeHandles .iterator(); iterator.hasNext();) {
IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
iAttribute = (IAttribute) teamRepository.itemManager().fetchCompleteItem( iAttributeHandle, IItemManager.DEFAULT ,null);
Identifier literalID = null;
IEnumeration<? extends ILiteral> enumeration = (IEnumeration<? extends ILiteral>) workItemClient.resolveEnumeration(iAttributeHandle, null);
List literals = enumeration.getEnumerationLiterals();
for(Iterator iterator1 = literals.iterator(); iterator1.hasNext();) {
ILiteral iLiteral = (ILiteral) iterator1.next();
if (((IPriority) iLiteral).getName().equals("High")) {
literalID = ((IPriority) iLiteral).getIdentifier2();
target=((IPriority) iLiteral).getName();
//System.out.println(literalID);
IWorkItem workItem1 = workItemClient.findWorkItemById(1468485,IWorkItem.FULL_PROFILE,null);
}
}
}
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
try {
WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
IWorkItem wcopy=wc.getWorkItem();
wcopy.setValue(iAttribute, target);
//updating description--working
String description=workItem.getHTMLDescription().getPlainText();
//wc.getWorkItem().setHTMLDescription(XMLString.createFromPlainText(description + "My description"));
//updating summary--working
String summary=workItem.getHTMLSummary().getPlainText();
//wc.getWorkItem().setHTMLSummary(XMLString.createFromPlainText(summary + "My Summary"));
//updating status--
IWorkflowInfo info= workItemClient.findWorkflowInfo(workItem,null);
// IAttribute at=(com.ibm.team.workitem.common.model.IAttribute)workItem.getState2();
// String status = info.getStateName(workItem.getState2());
// String value=new String("Start Working");
// if(value instanceof String)
{
workItem.setValue(at,value);
}
workItem.setState2((Identifier<IState>)com.ibm.team.workitem.taskWorkflow.action.a2);
// System.out.println("Status: " + status) ;
IDetailedStatus s = wc.save(null);
if (!s.isOK()) { throw new TeamRepositoryException("Error saving work item",
s.getException());
}
}
finally { wcm.disconnect(workItem);
}
System.out.println("Modified work item: " + workItem.getId() + "."); }
else{
break;
}
2 answers
The code is pretty unreadable.
You seem iterate all work item attributes and try to access that as an enumeration? That will not work. You will have to check if they are actually enumerations or something else.
Since you are a beginner, provide the attribute ID where you know it is an enumeration, same for the a
other attributes you look for. Also focus on one attribute first to get working code as described in https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ . Use instanceof to test for types/interfaes
Object value = workItem.getValue(customString);
if (value instanceof String) {
String attributeValue = (String) value;
// do something with the value
}
</pre>
</div>
PS: you have to look up the attribute ID's for the internal attributes in the Web Admin UI, and not in the Eclipse UI.
List builtInAttributeHandles = workItemClient.findAttributes(area, null);
for (Iterator iterator = builtInAttributeHandles .iterator(); iterator.hasNext();) {
IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
iAttribute = (IAttribute) teamRepository
.itemManager().fetchCompleteItem(
iAttributeHandle, IItemManager.DEFAULT ,null);
Identifier literalID = null;
if(iAttribute.getDisplayName().equals("Priority")){
IEnumeration<? extends ILiteral> enumeration = (IEnumeration<? extends ILiteral>) workItemClient.resolveEnumeration(iAttributeHandle, null);
//List literals = enumeration.getEnumerationLiterals();
for(ILiteral ilteral:enumeration.getEnumerationLiterals())
{
if((boolean)ilteral.equals("priority.literal.l11"))
target=((IPriority) ilteral).getName();
//IWorkItem workItem1 = workItemClient.findWorkItemById(1468485,IWorkItem.FULL_PROFILE,null);
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
try {
WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
IWorkItem wcopy=wc.getWorkItem();
wcopy.setValue(iAttribute,target);