It's all about the answers!

Ask a question

Change value of workitem in Follow-up action not apply!!!


silencehill wu (5022632) | asked Nov 14 '13, 4:04 a.m.

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


permanent link
Ralph Schoon (63.1k33645) | answered Nov 15 '13, 4:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 15 '13, 4:22 a.m.
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

Comments
silencehill wu commented Nov 16 '13, 5:08 a.m.

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?


Ralph Schoon commented Nov 18 '13, 2:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


silencehill wu commented Nov 25 '13, 11:42 a.m.

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?


sam detweiler commented Nov 25 '13, 11:48 a.m.

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
Aradhya K (1.4k44345) | answered Nov 14 '13, 4:19 a.m.
JAZZ DEVELOPER
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.

Comments
silencehill wu commented Nov 14 '13, 10:58 a.m. | edited Nov 14 '13, 11:27 a.m.

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.


Aradhya K commented Nov 14 '13, 10:54 p.m.
JAZZ DEVELOPER

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 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.