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 |