How do I reference a work item using Java API
Hi
I am trying to sync two work items on different project area . The requirement is fairly simple, all I need to do is when the work item B is saved , the comments and status should be reflected in work item A. I was able to get the details of work item B when the save is invoked. but I am not sure How I can provide the reference to work item A . so that I can update. I have the numeric value of workitem ID of A which is stored in B as a comment. I did saw IWorkItemHandle api , but could not make much use , as I got lost without javadoc. Any help is appreciated Thanks & Regards Jagadish |
6 answers
Jagadish,
client and server provide different APIs for modifying a work item. In the following example snippet I assume your code is invoked on the the client-site: ITeamRepository repository= <YOUR_REPOSITORY>; IWorkItemClient itemClient= (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class); IWorkItemWorkingCopyManager copyManager= itemClient.getWorkItemWorkingCopyManager(); IWorkItemHandle handle= itemClient.findWorkItemById(<YOUR_ITEM_ID>, IWorkItem.FULL_PROFILE, <YOUR_MONITOR>); try { copyManager.connect(handle, IWorkItem.FULL_PROFILE, <YOUR_MONITOR>); WorkItemWorkingCopy itemCopy= copyManager.getWorkingCopy(handle); IWorkItem itemToBeModified= itemCopy.getWorkItem(); // modify the item's attributes itemCopy.save(<YOUR_MONITOR>); } finally { copyManager.disconnect(handle); } On the client-site you need to create of copy of your work item A before you can modify it. Replace <YOUR_ITEM_ID> with the numeric ID of item A and update it's attributes. Note the FULL_PROFILE used here should be replaced with a profile more suitable to your purpose. HTH, Jan. -- Jan Wloka Jazz Work Item Team On Mon, 28 Dec 2009 07:06:51 +0100, jramakri <jramakri> wrote: Hi |
Hi Jan,
Many thanks for the response. The code is invoked from the server-side , so if we do it from the server side .. so any API similar to "findWorkItemById" on server side Thanks & Regards Jagadish Jagadish, Hi |
Jagadish,
the sever-side API is very similar. If the enclosing class is a service then you can find a work item by its numeric ID and modify it as follows: IWorkItemServer itemServer= getService(IWorkItemServer.class); itemServer.findWorkItemById(<YOUR_ITEM_ID>, IWorkItem.FULL_PROFILE, null); IWorkItem itemCopy= (IWorkItem)item.getWorkingCopy(); // modify itemCopy's attributes IStatus result= itemServer.saveWorkItem2(itemCopy, null, null); if (!result.isOK()) { // deal with errors } If you do modify references/links to the work item, saveWorkItem2() needs to receive the references in the second parameter. HTH, Jan. -- Jan Wloka Jazz Work Item Team On Mon, 04 Jan 2010 06:50:06 +0100, jramakri <jramakri> wrote: Hi Jan, |
Hi Jan,
Many Thanks for the reply . I will try the server side API, However I did something little crazy stuff . I used the Client API for the Workitem Save (server) side Operation behavior and was able to connect to any repository and sync with destination work item . However for this plugin to work , I had to deploy some of client jar files (around 12 ) on the server so that the API's are made available to the plugin I did see some exceptions on Jazz.log , but I did not notice any behavior change (ofcourse I concentrated on just open/save/modify of work items) Though my plugin is working .. I still feel this is not a clean way .. Wanted your expert opinion Thanks & Regards Jagadish Jagadish, Hi Jan, |
Jagadish, Hi ohhh thanks for the example I was looking for a workitem update example a lot of time. I didn't find any similar on the example snippets. Just creation of WI but not update. Thanks |
IWorkItemClient itemClient= (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class); The method findWorkItemById() from class IWorkItemClient returns a IWorkItem and not a IWorkItemHandle. The correct way should be: IWorkItemClient itemClient= (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class); or even your code is correct? In fact, Java compiler doesn't bother with your code... Thanks in advance. |
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.