It's all about the answers!

Ask a question

Get the Attributes Value for a given WorkItem in Java Plain API


Tiago Fernandez (5331619) | asked Aug 12 '13, 4:57 p.m.

Hello, I have a simple question for you surely, but since I'm brand new I don't know how to do it.

How to get the value of any attribute of a WorkItem with Plain Java API?

I already have the workitem in my code with:

workItem = workItemClient.findWorkItemById(workItemNumber, IWorkItem.FULL_PROFILE, new SysoutProgressMonitor())

but now I want to show some of its attributes with its values and I don't know how to continue.

Thanks for the help.

Accepted answer


permanent link
sam detweiler (12.4k6179201) | answered Aug 12 '13, 5:07 p.m.
see the second post here.. how to dump all the attributes via the plain java client api

https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes
Tiago Fernandez selected this answer as the correct answer

Comments
Tiago Fernandez commented Aug 12 '13, 9:31 p.m.

Thanks for the reply, but as I mentioned at the begining, I am brand new and in that post there are plenty lines of code.

Could you specify a very simple example in a couple a lines on how to get the value of any attibute given a workItem?

Thank you.

3 other answers



permanent link
sam detweiler (12.4k6179201) | answered Aug 13 '13, 8:11 a.m.
I hear you, but there is no 'simple' few statement example.

the routine that does the attribute work is
<code>
  static void printAttributes(IWorkItem workItem,
            IAuditableClient auditableClient, IProjectArea projectArea,
            org.eclipse.core.runtime.IProgressMonitor monitor, ITeamRepository repository, String XML)
    { 
    }
</code>
it loops thru all the attributes and handles each one on the fly.

but you will need to have the project area and the AuditableClient  library handle.

Comments
Tiago Fernandez commented Aug 13 '13, 2:53 p.m.

Yes, there is a simple way, I figured out myself.

It is in the next answer...


permanent link
Tiago Fernandez (5331619) | answered Aug 13 '13, 2:55 p.m.

I figured out myself, thanks.

Following some examples (they are in Groovy since I am working on that lengauge, similar to Java):

// Getting the workItem
workItem = workItemClient.findWorkItemById(workItemNumber, IWorkItem.FULL_PROFILE, new SysoutProgressMonitor())
  println("WorkItem found: ["+workItem.getId()+"] "+workItem.getHTMLSummary().getPlainText())  

//Getting the WorkItem Owner
  owner = workItem.getOwner()
  def iContributor = (IContributor) repo.itemManager().fetchCompleteItem(owner, IItemManager.DEFAULT, null);
  def owner = iContributor.getName();
  println("Owner is: " + owner)


//Getting the WorkItem Project Area
  def projectArea = workItem.getProjectArea()
  def iProjectArea  = (IProjectArea) repo.itemManager().fetchCompleteItem(projectArea, IItemManager.DEFAULT, null);
  projectArea = iProjectArea.getName();
  println("Project Area is: " + projectArea)
  

//Geting the WorkItem State
  IWorkflowInfo info= workItemClient.findWorkflowInfo(workItem, new SysoutProgressMonitor());
  def status = info.getStateName(workItem.getState2());
  println("Status: " + status)  


permanent link
sam detweiler (12.4k6179201) | answered Aug 13 '13, 2:59 p.m.
no problem.. same code as in my example.  I handle it by looking at the attribute type, then switching() based on the type to the right routine.

Your answer


Register or to post your answer.