Creating follow up condition to create approval records
Hi,
I am trying to write a follow up condition to generate approval records on transition to a particular state.
I got the new state and was able to compare it and now when i am trying to create approval records and trying to save WI using
IWorkItemServer workItemServer= getService(IWorkItemServer.class);
IStatus status =workItemServer.saveWorkItem2(workItem, null, null);
I am getting staleDataException. Pls help me on this.
Thanks
I am trying to write a follow up condition to generate approval records on transition to a particular state.
I got the new state and was able to compare it and now when i am trying to create approval records and trying to save WI using
IWorkItemServer workItemServer= getService(IWorkItemServer.class);
IStatus status =workItemServer.saveWorkItem2(workItem, null, null);
I am getting staleDataException. Pls help me on this.
Thanks
2 answers
I had this problem too - originally I was using ISaveParameter.getNewState() method to retrieve the work item object. It turns out this gets the state of the object before it is persisted into the repository. Try something like this instead:
This gets you a fresh copy of the work item from the repository to work with.
Hope this helps.
Simon
IWorkItem newState = (IWorkItem)saveParameter.getNewState();
IWorkItem workItem = (IWorkItem)wiService.findWorkItemById(
newState.getId(), IWorkItem.FULL_PROFILE, monitor).getWorkingCopy();
IStatus status =workItemServer.saveWorkItem2(workItem, null, null);
This gets you a fresh copy of the work item from the repository to work with.
Hope this helps.
Simon
Thanks a lot.This is exactly what i was looking for.
I had this problem too - originally I was using ISaveParameter.getNewState() method to retrieve the work item object. It turns out this gets the state of the object before it is persisted into the repository. Try something like this instead:
IWorkItem newState = (IWorkItem)saveParameter.getNewState();
IWorkItem workItem = (IWorkItem)wiService.findWorkItemById(
newState.getId(), IWorkItem.FULL_PROFILE, monitor).getWorkingCopy();
IStatus status =workItemServer.saveWorkItem2(workItem, null, null);
This gets you a fresh copy of the work item from the repository to work with.
Hope this helps.
Simon