FollowUp action
![]()
hi all,
it's possible programmatically modify the value for a custom attributes or bult-in attributes (like summary, description,...) in a follow up action on Save Work Item (server) operation? I have tried so:
but I have this exception: com.ibm.team.repository.common.StaleDataException: Stale Data :(((( Any suggestion? Thanks Andrea |
8 answers
![]() We got a Stale Data exception if we use:
to fetch the working copy of a work-item. Instead, if we use:
the update of the work-item works properly. Thanks to Patrick Streule for his tip: https://jazz.net/forum/questions/40205/followup-action/40208 Cheers. |
![]()
Ralph Schoon (63.3k●3●36●46)
| answered Jul 10 '12, 4:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Thanks for the answer.
Not sure if this can help, but I tend to not use the working copy manager, working copy and save anymore. Following https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation I use an WorkItemOperation to wrap the modification, similar to the creation in the examples presented in the link above. My assumption is that it helps me sticking to the rules, even if they change better, since the framework parts is handled by the operation code. This is the inner class implementing the operation. Please note the Load profile in the constructor. private static class WorkItemModification extends WorkItemOperation { private String fAttributeID; private Object fValue; public WorkItemModification(String attributeID, Object value) { super("Modifying Work Item",IWorkItem.FULL_PROFILE); fAttributeID=attributeID; fValue=value; } @Override protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException { IWorkItem workItem = workingCopy.getWorkItem(); ITeamRepository teamRepository = (ITeamRepository)workItem.getOrigin(); IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class); IAttribute attribute = workItemClient.findAttribute(workItem.getProjectArea(), fAttributeID, monitor); if(null!=attribute){ if(workItem.hasCustomAttribute(attribute)) workItem.setValue(attribute, fValue); } } This is how it gets called: IWorkItem workItem = workItemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, monitor); WorkItemModification operation = new WorkItemModification("anAttributeID","someValue"); operation.run(workItem, monitor); |
![]()
I tried this simple code but still does not work:
package com.ibm.rational.rtc.docreview; At first time that I save my work item, the description changes. The second time that I save my work item, the description don't changes and I found this exception "Stale Data". osgi> |
![]()
Andrea,
in general I'd say yes. It's looks like your code is run before the item is written to the repository, i.e., the item was modified and should be a working copy already. Try to manipulate and save the data you get from the operation directly. HTH, Jan. -- Jan Wloka Jazz Tracking & Planning Team hi all, |
![]()
Every time an item is saved, a new state is created. When you save an item, the newest state must be used, otherwise you get a StaleDataException.
When you save an item more than once, you will need to make sure that you always have the latest state by: - either use the item returned by the save call - fetch the item from the repository again |
![]()
Thanks to all!
I solved so:
|
![]()
Hi Andrea, I'm facing few issues in creating a work item programmatically using operation participant.
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import com.ibm.team.process.common.IProcessConfigurationElement; import com.ibm.team.process.common.IProjectAreaHandle; import com.ibm.team.process.common.advice.AdvisableOperation; import com.ibm.team.process.common.advice.IReportInfo; import com.ibm.team.process.common.advice.runtime.IOperationParticipant; import com.ibm.team.process.common.advice.runtime.IParticipantInfoCollector; import com.ibm.team.repository.common.IAuditable; import com.ibm.team.repository.common.TeamRepositoryException; import com.ibm.team.repository.service.AbstractService; import com.ibm.team.workitem.common.ISaveParameter; import com.ibm.team.workitem.common.IWorkItemCommon; import com.ibm.team.workitem.common.model.IAttribute; import com.ibm.team.workitem.common.model.IWorkItem; import com.ibm.team.workitem.common.model.IWorkItemType; import com.ibm.team.workitem.service.IWorkItemServer; public class AutomaticProhibitSave extends AbstractService implements IOperationParticipant { public void run(AdvisableOperation operation, IProcessConfigurationElement participantConfig, IParticipantInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException { // TODO Auto-generated method stub Object data = operation.getOperationData(); if (data instanceof ISaveParameter) { ISaveParameter param = (ISaveParameter) data; IAuditable auditable = param.getNewState(); if (auditable instanceof IWorkItem) { IWorkItem sourceworkItem = (IWorkItem) auditable; IProjectAreaHandle projectArea = sourceworkItem.getProjectArea(); String parentWItype= sourceworkItem.getWorkItemType(); String parent = "com.ibm.team.apt.workItemType.epic"; if (parent.equalsIgnoreCase(parentWItype)) { String targetWorkItemType = "com.ibm.team.apt.workItemType.story"; IWorkItemServer workItemServer = this.getService( IWorkItemServer.class ); IWorkItemCommon workItemCommon = this.getService( IWorkItemCommon.class ); IWorkItemType child= workItemCommon.findWorkItemType( projectArea, targetWorkItemType, monitor ); IWorkItem targetWorkItem = workItemServer.createWorkItem2(child); //Assigning attribute values String attributeId = "summary" ; String attributeValue = "Programmatic Story 1"; IAttribute attribute = workItemCommon.findAttribute( projectArea, attributeId, monitor ); targetWorkItem.setValue( attribute, attributeValue ); String attributeId2 = "test" ; String attributeValue2 = "Test 1"; IAttribute attribute2 = workItemCommon.findAttribute( projectArea, attributeId2, monitor ); targetWorkItem.setValue( attribute2, attributeValue2 ); //Saving the child story WI IWorkItem workItemForUpdate = (IWorkItem)targetWorkItem.getWorkingCopy(); IStatus status= workItemServer.saveWorkItem2( workItemForUpdate, null,null ); if (!status.isOK()) { // TODO: Handle the exception } } else { IReportInfo problem = collector.createExceptionInfo( "Work item is of type: " + sourceworkItem.getWorkItemType(),new Exception("Error")); collector.addInfo(problem); } } } } } Thanks to all! |
![]()
Hi, I tried to create a story WI(programmatically) whenever i create an epic and save it. But its not allowing me to save the epic WI.
Please look at my code and correct me if i'm wrong, since i'm new to this!! Thanks in advance!! |
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.