It's all about the answers!

Ask a question

find (back) a woirk item by its ID


Christophe Doré (63) | asked Jun 02 '08, 10:40 a.m.
Hi

I've created a small jazz UI plugin that allow the user to create
some work items based on some info from a Database.

I'd like to allow the user to find back a work item when he connects
later to another TeamConcert session. I can store the ID of the work
item when I create it, but how can I retreive a work item given its ID?

Could you show me some code snippets?

thanks for your help

--
cd

3 answers



permanent link
Kai Nehring (3116) | answered Jun 02 '08, 12:53 p.m.
Hi,

You could use a query to find your Work Items but I think that's overkill if you just want one and you know the ID. I've written a small function for this once that might help you:


public IWorkItem getWorkItemByID(int id) {
IWorkItem workItem = null;
IWorkItemClient workItemClient = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);

try {
workItem = workItemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, monitor);
} catch (TeamRepositoryException e) {
log.severe(e.getMessage());
}

return workItem;
}







I hope that will help you

Kai



Hi

I've created a small jazz UI plugin that allow the user to create
some work items based on some info from a Database.

I'd like to allow the user to find back a work item when he connects
later to another TeamConcert session. I can store the ID of the work
item when I create it, but how can I retreive a work item given its ID?

Could you show me some code snippets?

thanks for your help

--
cd

permanent link
Stefan Xenos (11) | answered Jun 02 '08, 5:48 p.m.
If you're just trying to store the same work item so you can recover it later, you might want to try saving its UUID instead of its ID. This is probably more efficient than searching by ID and will work with all auditable types - not just work items:


// How to save it:
UUID myId = workItem.getItemId();
String asString = myId.toString();

// How to restore it:
String someWorkItemUUID = ...
ITeamRepository repo = ...

UUID id = UUID.valueOf(someWorkItemUUID);
IWorkItemHandle handle = IWorkItem.ITEM_TYPE.createItemHandle(id, null);
IWorkItem workItem = repo.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, progressMonitor);

// ...and now you've got your IWorkItem back...

permanent link
Christophe Doré (63) | answered Jun 06 '08, 11:51 a.m.
Hi

It just works fine.

Thanks!

--
cd
sxenos a crit :
If you're just trying to store the same work item so you can recover
it later, you might want to try saving its UUID instead of its ID.
This is probably more efficient than searching by ID and will work
with all auditable types - not just work items:


// How to save it:
UUID myId = workItem.getItemId();
String asString = myId.toString();

// How to restore it:
String someWorkItemUUID = ...
ITeamRepository repo = ...

UUID id = UUID.valueOf(someWorkItemUUID);
IWorkItemHandle handle = IWorkItem.ITEM_TYPE.createItemHandle(id,
null);
IWorkItem workItem = repo.itemManager().fetchCompleteItem(handle,
IItemManager.DEFAULT, progressMonitor);

// ...and now you've got your IWorkItem back...

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.