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

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.

0 votes


Accepted answer

Permanent link
I have to disagree, you are not supposed to change the data of a work item in an advisor/pre condition. See: https://rsjazz.wordpress.com/2012/12/14/do-not-modify-the-triggering-element-in-an-operationadvisor/

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.
silencehill wu selected this answer as the correct answer

0 votes

Comments

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?

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.

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?

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

Permanent link
HI
If you are trying to update the work item then it would be better if it is done in the advisor than in the follow up action.
The usual flow is during the save operation all the pre conditions are first executed, then the work item will be saved on to the repository, after this the follow up actions will be invoked.

0 votes

Comments

Yes, I know you mean.  

But my business logic like below:
1. create/ update work item finished.
2. User can change work item state and click save. If work item saved succcessly,  A new stream  will be auto created according to the work item information .
3. If  stream created success or fail, a special attribute of  work item to indicate stream creation is ok or failed  will be updated. Actually, business logic is more complex, I just try to describe it simple to understand.

So I have to coding in  follow up action, step 2, step 3 all need to be coding in follow up action.

So how can I change workitem values in follow up action.

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.

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
× 10,954

Question asked: Nov 14 '13, 4:04 a.m.

Question was seen: 5,716 times

Last updated: Nov 25 '13, 11:48 a.m.

Confirmation Cancel Confirm