Change value of workitem in Follow-up action not apply!!!
![](http://jazz.net/_images/myphoto/89dc95b435bb5b04a996d711c1703686.jpg)
I am writting a Follow-up action.I want to modified value of two field after the change of any field value of workitem saved. But after changing state of the workitem, the follow action did run, and set setAttribute statement did passed. After follow up action finished. In UI of RTC client, The two fields were not changed at all. The type of two fields both are small string. Why no change? how can I change workitem values in follow up action.
Please do not let me try pre condition. Pre-condition is ok, I know. But I want to change value of workitem just after workitem have been saved. I need do some other work after workitem saved not before workitem saved.
The source like below:
public class StreamAutoCreateParticipant extends AbstractScmService implements IOperationParticipant {
private static Logger logger = Logger.getLogger(StreamAutoCreateParticipant.class);
private static IWorkItemServer workItemService;
private static IProjectAreaHandle projectAreaHandle;
private static IProcessService processService;
@SuppressWarnings("unchecked")
@Override
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor progress)
throws TeamRepositoryException {
IRepositoryItemService repoItemService = getService(IRepositoryItemService.class);
workItemService = getService(IWorkItemServer.class);
Object operationData = operation.getOperationData();
if (!(operationData instanceof ISaveParameter)) {
return;
}
IProcessArea processArea = operation.getProcessArea();
projectAreaHandle = processArea.getProjectArea();
IProjectArea projectArea = (IProjectArea) repoItemService.fetchItem(processArea.getProjectArea(),IRepositoryItemService.COMPLETE);
IWorkItem newWorkItem = (IWorkItem) saveParameter.getNewState();
IAttribute attr = workItemService.findAttribute(projectArea, "SupplementalProduct", null);
workItem.setValue(attr, "abcd,ddd,tttt");
IAttribute attr = workItemService.findAttribute(projectArea, "MainProduct", null);
workItem.setValue(attr, "kkkk");
logger.info("########StreamAutoCreateParticipant结束,vpproject工作项状态修改之后自动创建流###############"+new Date());
}
after the source running, the value of SupplementalProduct and MainProduct still not changed.
then I have ever change coding like below, but cycling happened, loop saving.
IWorkItem wk = workItemService.findWorkItemById(newWorkItem.getId(), IWorkItem.FULL_PROFILE, null);
IWorkItem workingCopy= (IWorkItem)wk.getWorkingCopy();
IAttribute attr = workItemService.findAttribute(projectArea, "MainProduct", null);
workingCopy.setValue(attr, "kkkk");
IStatus status = workItemService.saveWorkItem2(workingCopy, null, null);
if(! status.isOK()) {
logger.error("########error,保存工作项失败###############");
}
then I try below code,but error occured,
IWorkItem newWorkItem = (IWorkItem) saveParameter.getNewState();
IWorkItem workingCopy= (IWorkItem)newWorkItem.getWorkingCopy();
IAttribute attr = workItemService.findAttribute(projectArea, "MainProduct", null);
workingCopy.setValue(attr, "kkkk");
error info :
14:15:26,421 [30252940@qtp-21488974-59] ERROR com.ibm.team.process.common - Stale Data
com.ibm.team.repository.common.StaleDataException: Stale Data
at com.ibm.team.workitem.service.internal.WorkItemServer.saveWorkItems(WorkItemServer.java:150)
at com.ibm.team.workitem.service.internal.WorkItemServer.saveWorkItem3(WorkItemServer.java:115)
at com.ibm.team.workitem.service.internal.WorkItemServer.saveWorkItem2(WorkItemServer.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Please give me an advise.
Accepted answer
![](http://jazz.net/_images/myphoto/89dc95b435bb5b04a996d711c1703686.jpg)
https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ , https://rsjazz.wordpress.com/2012/11/27/resolve-parent-if-all-children-are-resolved-participant/ , https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/ show examples where the work item gets updated. You get stale data, if the data in the work item is not the most recent. Try to resolve the work item again, before you modify it.
Comments
![](http://jazz.net/_images/myphoto/89dc95b435bb5b04a996d711c1703686.jpg)
You mean I can get the workitem the lastest like below:
IWorkItem workingCopy = WorkItemServer
.getAuditableCommon()
.resolveAuditable( (IWorkItem) saveParameter.getNewState(), IWorkItem.FULL_PROFILE, monitor)
.getWorkingCopy();
then call
workItemServer.saveWorkItem2(workingCopy, null, null);
will save the change of value?
![](http://jazz.net/_images/myphoto/e5e63d5878217b64611c1df9401b7cd3.jpg)
I mean, stale data says that the item has been modified somewhere else. So before you get the working copy get the work item again, then do the modification and save. You can see in my posts how I do it.
![](http://jazz.net/_images/myphoto/89dc95b435bb5b04a996d711c1703686.jpg)
Thks, it has worked in follow action to refer your post.
But I still have a question, why we can set attribute value directly using setAttribute api without call save api, and it can work immediately in pre-condition, why setAttribute API can not work in follow action directly?
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
the attribute should not change in the database unless a workitem Save has been completed.
setAttribute changes the in memory copy, but not the database.
One other answer
![](http://jazz.net/_images/myphoto/89dc95b435bb5b04a996d711c1703686.jpg)
Comments
![](http://jazz.net/_images/myphoto/89dc95b435bb5b04a996d711c1703686.jpg)
Yes, I know you mean.
![](http://jazz.net/_images/myphoto/7f47bbe8b44dabecf28a53c20079fa14.jpg)
There is not much difference between creating other artifacts as part of the advisors or participants. But if you want to update the work item in transaction then it would be better if done in the advisor.