Change value of workitem in Follow-up action not apply!!!
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
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.