Can we update defect through IWorkItemSave followup action
![]()
Riddhi Shah (37●2●15●18)
| asked Aug 06 '12, 9:11 a.m.
edited Aug 06 '12, 1:17 p.m. by Jared Burns (4.5k●2●9)
Hi,
I need to update state of RTC Defect on save operation. For example, If user has moved status to "Reopen", description should be updated with "Reopen template" automatically. Is it possible to write followup action plugin for IWorkItemSave ? If I try to update defect through OSLC service in "IWorkItemSave" followup plugin , it gives error of can not acquire lock in database. - Riddhi |
4 answers
![]()
a participant (followup action) CAN update this or other workitems.
the saveworkitem2() call will cause ANOTHER trip thru the advisor and participants chain. recursively. so, it is recommended (required?) to use saveWorkitem3() which takes a last parameter to pass a flag to the newly invoked participant to ignore. (else, you save recursively until you run out of stack and cause an exception. see https://jazz.net/forum/questions/94075/how-to-get-custom-attribute-value-with-java-api |
![]()
Hey Riddhi,
As stated in the Javadoc in com.ibm.team.workitem.service.IWorkItemPostSaveParticipant a work item post save participant is not allowed to change the state of the work item. /**... * A work item post-save participant is run after a work item has been successfully saved.Unfortunately, there is no actual save participant for work items ( as of RTC 4.0.1 ). You can only "veto" the save action either before the save action, or after the save action. If you need to perform something relatively simple, your best approach would be to use a Script based calculated value (Under Attribute Customization) which runs on every save action on a given attribute. |
![]()
Hi David,
Event with java api, If I try to update my defect on followup action ( operation participant plugin on workitem save) it does not update the state of it. Following is my code for plugin: 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 saveParameter = (ISaveParameter) data; IAuditable auditable = saveParameter.getNewState(); if (auditable instanceof IWorkItem) { workItemServer = getService(IWorkItemServer.class); wiCommon = getService(IWorkItemCommon.class); IWorkItem workItem = (IWorkItem) auditable; IWorkItem workItemWC = (IWorkItem)workItem.getWorkingCopy(); if (workItemWC == null) { System.out.println("Work Item not found."); return; } try { IAttribute summaryAttribute = wiCommon.findAttribute(workItemWC.getProjectArea(),SAVE_SUMMARY, monitor); workItemWC.setValue(summaryAttribute, "updated from plugin"); workItemServer.saveWorkItem2(workItemWC, null, null); } catch (Exception e) { e.printStackTrace(); } } } Above code works fine and auto updates summary on create of Defect. But on all subsequent updates it does not update summary. |