It's all about the answers!

Ask a question

How can i update the status and priority and severity and iteration of a workitem?


Anirban Roy (1318) | asked Jun 19 '17, 7:15 a.m.

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



permanent link
Ralph Schoon (63.1k33646) | answered Jun 19 '17, 9:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jun 19 '17, 9:47 a.m.

 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.


Comments
Anirban Roy commented Jun 20 '17, 1:45 a.m.

i am bale to get all the priorities but i am not able to type cast it from com.ibm.team.workitem.common.internal.model.Priority to com.ibm.team.repository.common.query.ast.ILiteral.Moreover setting the value also shows error.please help me





 



permanent link
Anirban Roy (1318) | answered Jun 20 '17, 1:45 a.m.
edited Jun 20 '17, 1:46 a.m.

 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);


Comments
Anirban Roy commented Jun 20 '17, 1:47 a.m.

 i am able to get all the priorities while debuggingin the list but i am not able to type cast it from com.ibm.team.workitem.common.internal.model.Priority to com.ibm.team.repository.common.query.ast.ILiteral.Moreover setting the value also shows error.please help me



Ralph Schoon commented Jun 20 '17, 4:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I think you should do some reading instead of creating code. I already provided you with https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ which also links to:  https://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/

Most links I provided you have downloadable code that works (for me at least) to deal with enumerations. 

My code does not use the WorkingCopyManager but a WorkItem Operation as explained in https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ .

So I would suggest to do some downloading, reading and experimenting with existent code. 

The work item command line code deals with all the problems you are facing too, but it is more complex and maybe looking into to special blog posts might be more effective.


Anirban Roy commented Jun 21 '17, 1:39 a.m.

 Hi Ralph,

I have read these documents.but still not able to update the status.Can u please help me with code how to update the status and type of a particular workitem


Ralph Schoon commented Jun 21 '17, 3:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.