It's all about the answers!

Ask a question

How to get and update the owner of the work item via Java API?


Jayee Huang (1321111) | asked Mar 08 '13, 11:02 a.m.
 I can get and update some string attributes of a work item via Java API. 
copiedWorkItem is the object of IWorkItem;
 String currentSummary = copiedWorkItem.getHTMLSummary().getPlainText().trim();
            if (!currentSummary.equalsIgnoreCase(workitem.getSummary().trim())){
                IAttribute summaryAttribute= workItemClient.findAttribute(projectArea, IWorkItem.SUMMARY_PROPERTY, monitor);
                copiedWorkItem.setValue(summaryAttribute, workitem.getSummary());
            }
But I cannot get and set the value of "Owner". Who can help me? 

Accepted answer


permanent link
Andrew Niefer (7135) | answered Mar 08 '13, 11:35 a.m.
JAZZ DEVELOPER
<tt>IWorkItem.getOwner()</tt> and <tt>IWorkItem.setOwner()</tt> deal with <tt>IContributorHandle</tt>, not strings.  I'm not really sure how this interacts with the <tt>OWNER_PROPERTY</tt> attribute.

Working with getOwner() would look something more like this:
IContributorHandle ownerHandle = workitem.getOwner();
//fetch the full object to see things like IContributor.getName(), IContributor.getUserId(), etc...
IContributor owner = teamRepository.itemManager().fetchCompleteItem(ownerHandle, IItemManager.DEFAULT, progressMonitor);

If you want to change the owner, use the IContributorManager to get the contributor:
IContributor newOwner = teamRepo.contributorManager().fetchContributorByUserId(newOwnerUserId, progressMonitor);
copiedWorkItem.setOwner(newOwner);


Jayee Huang selected this answer as the correct answer

Comments
Jayee Huang commented Mar 11 '13, 11:15 a.m.
I meet a new problem, I cannot find the right API to get and update status of a work item. 
Andrew, do you know about that?

One other answer



permanent link
Jayee Huang (1321111) | answered Mar 11 '13, 5:13 a.m.
Thanks Andrew. I used this in my project and it worked.
But I think it is very hard to find the correct API with clear specification.

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.