Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.


0 votes


Accepted answer

Permanent link
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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Aug 24 '12, 7:09 a.m.

Question was seen: 2,961 times

Last updated: Aug 27 '12, 5:11 a.m.

Confirmation Cancel Confirm