ISaveParameter.getOldState()
I have a Follow-up action on the Save Work Item (server) operation. I need to determine if the workitem has just had its 'Owned By' field set from 'Unassigned' to an assigned user.
I attempt to determine this by getting the 'before' state of the workitem (getOldState()) and the 'after' state (getNewState()), resolving the handles into workitems... then finally calling getOwner() on each workitem. What I am seeing in the follow-up action is that the getOwner() call is always returning the 'new' owner just set in this save operation. It is not returning the 'before' owner. I am using RTC 1.0.1. Here is the code I have inside of the run() method of my AbstractService subclass (the two IContributorHandle fields are always the same on every workitem save): Object data = operation.getOperationData(); ISaveParameter saveParameter = (ISaveParameter) data; IAuditableCommon auditableCommon = fservice.getService(IAuditableCommon.class); IAuditable auditable = saveParameter.getNewState(); IWorkItemHandle handle = (IWorkItemHandle)auditable.getItemHandle(); IWorkItem workItem = auditableCommon.resolveAuditable(handle,IWorkItem.FULL_PROFILE, monitor); IAuditable auditablePrevious = saveParameter.getOldState(); IWorkItemHandle handlePrevious = (IWorkItemHandle)auditablePrevious.getItemHandle(); IWorkItem workItemPrevious = auditableCommon.resolveAuditable(handlePrevious,IWorkItem.FULL_PROFILE, monitor); IContributorHandle ownerPrevious = workItemPrevious.getOwner(); IContributorHandle owner = workItem.getOwner(); return; |
4 answers
IAuditable auditablePrevious = saveParameter.getOldState(); Resolving an item using 'resolveAuditable' will always return the latest state. If you change the above code to IWorkItem workItemPrevious= (IWorkItem) saveParameter.getOldState(); you will be able to get the previous owner from 'workItemPrevious'. -- Regards, Patrick Jazz Work Item Team |
Hi
When resolving an item, you will always get the current state. You need to resolve the handle by providing the state that you are interested in (e.g. ItemManager#fetchPartialState). However the getOldState and getNewState methods on ISaveParameter already return the resolved items, you can cast them to IWorkItem directly. e.g. IWorkItem workItem= (IWorkItem)saveParameter.getNewState(); Regards Marcel Jazz Work Item team |
Thanks for your quick reply. Your solution solved my problem.
Dave |
I'm wondering if my issue is that my code is in an operation participant. So by the time my code triggers, the work item has already been saved. Therefore the "current state" and the "previous state" are the same at this point. Is that the likely source of my issue? I really need to get the previous state though. Specifically, I need the links that were there previously. I can't use the history for this since Links don't leave a history trail. Is this just impossible with an Operation Participant? Is there a way for an advisor to save information in some sort of cache that a participant can read from later? Edit: This DOES appear to be working. My problem was I hadn't safeguarded the follow up action from triggering itself upon save. It was printing out over a page of debug messages so I didn't realize I was looking at the results of the self-triggered action rather than the initial one. Note that although I can get the previous description information, it doesn't appear that I can get the previous links. Comments 1
sam detweiler
commented Jul 09 '14, 12:54 p.m.
my participants depend on oldstate being before the save.
Nate Decker
commented Jul 09 '14, 1:24 p.m.
I'm on 4.0.6.
sam detweiler
commented Jul 11 '14, 12:14 p.m.
correct, links are not maintained as part of change history
Nate Decker
commented Jul 11 '14, 12:22 p.m.
So are you saying there is no way to get the links state from before the work item was changed? I kind of need that... I didn't get the impression that "getOldState" was leveraging the work item history, I figured it was some sort of cached copy before the workitem save was committed to the database. Are you sure links aren't accessible in some fashion? I found another post that suggested you could cast the saveParameter to WorkItemReferences and then use "getCreatedReferences" and "getDeletedReferences". In particular, "getDeletedReferences" seems really promising. It didn't work for me though. If that's not the purpose of getDeletedReferences, I don't know what is.
sam detweiler
commented Jul 11 '14, 12:58 p.m.
I don't know either. but you 'might' be able to compare oldstate deleted references as compared to newstate deleted references
|
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.