How to get previous values (state) of an ITimeSheetEntry?
I'm developing an IOperationParticipant that needs to detect the exact change on time tracking.
In order to get previous values of an WorkItem attribute inside an IOperationParticipant, I simply use:
IWorkItem oldWorkItem = (IWorkItem) saveParameter.getOldState();
But as far as I know, ITimeSheetEntry is linked to a WorkItem using endpoint
I tried this, but obviously didn't work, because it gets the current values of the links:
List<ITimeSheetEntry> listTimeChildren = new ArrayList<ITimeSheetEntry>();
IWorkItemServer service = getService(IWorkItemServer.class);
IWorkItemReferences workItemReferences = service.resolveWorkItemReferences(oldWorkItem , null);
List<IReference> listReferences = workItemReferences.getReferences(WorkItemEndPoints.WORK_TIME);
for (IReference reference : listReferences) {
if (reference.isItemReference()) {
referencedItem = ((IItemReference) reference).getReferencedItem();
if (referencedItem instanceof ITimeSheetEntryHandle) {
timeChild = (ITimeSheetEntry) repositoryItemService.fetchItem(referencedItem, null);
listTimeChildren.add(timeChild);
}
}
}
For new or deleted ITimeSheetEntry, I can use
3 answers
This is an old question, but for anyone that is still wondering, I have a more direct way than looking at the recently modified timesheets.
IWorkItemServer service = getService(IWorkItemServer.class);
ArrayList<IReference> newLinks = new ArrayList<IReference>();
ArrayList<IReference> oldLinks = new ArrayList<IReference>();
IWorkItemReferences newReferences = saveParameter.getNewReferences();
newLinks.addAll(newReferences.getReferences(WorkItemEndPoints.WORK_TIME));
if(saveParameter.getOldState() != null) {
IWorkItem previousWI = (IWorkItem) (saveParameter.getOldState());
IWorkItemReferences oldReferences = service.resolveWorkItemReferences((IWorkItemHandle) previousWI.getItemHandl(), monitor);
oldLinks.addAll(oldReferences.getReferences(WorkItemEndPoints.WORK_TIME));
}
As usual, remember that if you are using the IWorkItemServer object, you'll need to add the "requiredService" node to the plugin.xml of your MANIFEST.MF file.
Comments
Rubin Zheng
Sep 01 '13, 3:17 a.m.Any idea? I have the same question.