Saving work Items simultaneously
![]()
I am developing a plugin for propagating changes from Blocks(say Master) Work Items to Dependent Work Items.
For instance: If I explain in generic sense then, Suppose there is some tree-structure where parent is called master work item and child is called as dependent work item. This tree structure holds only TASK WORK ITEMS. I want to propagate values of some attribute say 'Comments' to dependents. So The approach which I am following is : When any task is saved and it has both master and dependent work items, Inside run method I am saving the reference of root of the tree and then I am calling one other method for recursion to access all work items in the tree and save the desired values. I am able to set the values but I am getting problem in saving workitems concurrently as it is calling same plugin again. The code which I have provided is to supply logic and doesn't contain all details of the code here. public void saveDependents(IWorkItem workItem,IProgressMonitor monitor) throws TeamRepositoryException { System.out.println("Inside saveDependents"); IWorkItemHandle iWorkItemHandle=null; ArrayList<IWorkItemHandle> dependentList = (ArrayList<IWorkItemHandle>) utilService.getDependentWorkItems(null,workItem); iterator = dependentList.iterator(); System.out.println(workItem.getId()); if(!iterator.hasNext()) { System.out.println("Dependent list is empty"); return; } while(iterator.hasNext()) { iWorkItemHandle = (IWorkItemHandle) iterator.next(); auditableCommon = getService(IAuditableCommon.class); dependentWorkItem = auditableCommon.resolveAuditable( iWorkItemHandle, IWorkItem.FULL_PROFILE, null); System.out.println("WI Before Save Dependents : "+dependentWorkItem.getId()); saveDependents(dependentWorkItem,monitor); } //This is the dummy code. if(workItem.getValue(comments) != null) { newComments = ((String)workItem.getValue(comments)); } utilService.saveWorkItemComments(dependentWorkItem,newComments, monitor); //I am calling saveWorkItem2() method in saveWorkItemComments() and applying this operation on working copy. } } So, The problem is that, Code is going in loop and accessing the leaf work items twice and giving stale data exception. Is there any way to save two work items simultaneously if I have the work items in a list. Or Do I need to change my approach to save the work items, because I read somewhere that saveWorkItem2() is used for saving the parent not the same work item. Kindly guide as I am unable to find any documentation on this. |
Accepted answer
![]()
Ralph Schoon (63.3k●3●36●46)
| answered Aug 27 '12, 5:11 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Sarthak,
please look at the forum posts around https://jazz.net/search_results.jsp?q=enumeration+database#page=0&type=&q=stale%20data%20exception The stale data basically happens if the work item working copy is not "fresh". See https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ how to fetch it again. You can only update one work item at any time, so the approach would be to fetch one, update it and the fetch the next etc. On the server you can use saveWorkItem2() and saveWorkItem3() it is not related to a parent work item, it saves a work item where you have a working copy. The blog post shows why using saveWorkItem3() could be an option. Sarthak Sharma selected this answer as the correct answer
|
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.