please help! cannot add/modify time sheets - ITimeSheetEntry
I'm trying to add and/or modify ITimeSheetEntry objects in RTC 3.0.1. I've tried a variety of different ways to create the references/links, but, it just doesn't seem to take. Using the code below:
I get the following exception:
One strange item of note is that if I create time sheet entries via the Eclipse client and query the references, I notice that they all have the same ItemId, yet, the createTimeSheetEntry line above creates a unique item id. Not sure if thats what the underlying problem is or not. Any help on this matter would be greatly appreciated, especially since the post here:
https://jazz.net/forums/viewtopic.php?t=18764
was never replied to :-(
IWorkItemHandle handle = (IWorkItemHandle)wi.getItemHandle();
//get the working copy manager
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
//connect to the copy manager
wcm.connect(handle, IWorkItem.FULL_PROFILE, monitor);
//get a working copy
WorkItemWorkingCopy wc = workItemClient.getWorkItemWorkingCopyManager().getWorkingCopy(handle);
//get our work item
IWorkItem wiCopy = wc.getWorkItem();
//get the "new" handle
handle = (IWorkItemHandle)wiCopy.getItemHandle();
//copy the references
IWorkItemReferences copyReferences = wc.getReferences();
//create a new time sheet entry
ITimeSheetEntry newEntry = workItemClient.createTimeSheetEntry(projectArea.getProjectArea());
newEntry.setTimeSpent(new Duration(1000L*60*60));
newEntry.setTimeCodeId("timecode.literal.l1");
newEntry.setStartDate(new Timestamp(now.getTime().getTime()));
newEntry.setCreator(wi.getCreator());
//create a new item ref
IItemReference timesheetRef = IReferenceFactory.INSTANCE.createReferenceToItem(newEntry);
copyReferences.add(WorkItemEndPoints.WORK_TIME, timesheetRef);
//save the workitem with the changes we've made
IDetailedStatus result = wc.save(monitor);
I get the following exception:
REFERENCED ITEM IS [class com.ibm.team.workitem.common.internal.model.impl.TimeSheetEntryHandleImpl]
com.ibm.team.repository.common.ItemNotFoundException: CRJAZ0215I The following record was not found in the database: com.ibm.team.workitem.common.internal.model.impl.TimeSheetEntryHandleImpl@1ee8c1 (stateId: <unset>, itemId: [UUID _cCrPAMprEeCtiMReqV6JAw], origin: com.ibm.team.repository.client.inte
rnal.TeamRepository@1bd523d, immutable: true)
at com.ibm.team.repository.client.internal.ItemManager.internalFetchItem(ItemManager.java:1602)
at com.ibm.team.repository.client.internal.ItemManager.access$1(ItemManager.java:1559)
at com.ibm.team.repository.client.internal.ItemManager$AbstractStore.retrieveItem(ItemManager.java:196)
at com.ibm.team.repository.client.internal.ItemManager$CurrentStore.fetchItem(ItemManager.java:321)
at com.ibm.team.repository.client.internal.ItemManager.fetchCompleteItem(ItemManager.java:845)
at com.ibm.ips.gui.rtc.RTC.retrieveAllUserWorkItems(com.ibm.ips.gui.rtc.RTC:822)
at com.ibm.ips.gui.threads.RTCRefreshThread.run(com.ibm.ips.gui.threads.RTCRefreshThread:190)
at java.lang.Thread.run(Thread.java:619)
One strange item of note is that if I create time sheet entries via the Eclipse client and query the references, I notice that they all have the same ItemId, yet, the createTimeSheetEntry line above creates a unique item id. Not sure if thats what the underlying problem is or not. Any help on this matter would be greatly appreciated, especially since the post here:
https://jazz.net/forums/viewtopic.php?t=18764
was never replied to :-(
4 answers
Just for anyone else that's ever trying to do this ... I got an answer back from someone in RTC -- turns out I was missing one, very much undocumented, piece of code:
//add the new entry
copyReferences.add(workTimeEndPoint, timesheetRef);
wc.getDependentItems().add(newEntry);
After I got things working with the above line of code, and further tested, I realized that RTC really requires you to additionally still maintain the total timeSpent field even when you update/add ITimeSheetEntry items. So, whenever you make changes, you'll want to re-calculate the timeSpent as well.
Hopefully that helps someone else out there.
Enjoy!
//add the new entry
copyReferences.add(workTimeEndPoint, timesheetRef);
After I got things working with the above line of code, and further tested, I realized that RTC really requires you to additionally still maintain the total timeSpent field even when you update/add ITimeSheetEntry items. So, whenever you make changes, you'll want to re-calculate the timeSpent as well.
Hopefully that helps someone else out there.
Enjoy!
I'm trying to add and/or modify ITimeSheetEntry objects in RTC 3.0.1. I've tried a variety of different ways to create the references/links, but, it just doesn't seem to take. Using the code below:
IWorkItemHandle handle = (IWorkItemHandle)wi.getItemHandle();
//get the working copy manager
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
//connect to the copy manager
wcm.connect(handle, IWorkItem.FULL_PROFILE, monitor);
//get a working copy
WorkItemWorkingCopy wc = workItemClient.getWorkItemWorkingCopyManager().getWorkingCopy(handle);
//get our work item
IWorkItem wiCopy = wc.getWorkItem();
//get the "new" handle
handle = (IWorkItemHandle)wiCopy.getItemHandle();
//copy the references
IWorkItemReferences copyReferences = wc.getReferences();
//create a new time sheet entry
ITimeSheetEntry newEntry = workItemClient.createTimeSheetEntry(projectArea.getProjectArea());
newEntry.setTimeSpent(new Duration(1000L*60*60));
newEntry.setTimeCodeId("timecode.literal.l1");
newEntry.setStartDate(new Timestamp(now.getTime().getTime()));
newEntry.setCreator(wi.getCreator());
//create a new item ref
IItemReference timesheetRef = IReferenceFactory.INSTANCE.createReferenceToItem(newEntry);
copyReferences.add(WorkItemEndPoints.WORK_TIME, timesheetRef);
//save the workitem with the changes we've made
IDetailedStatus result = wc.save(monitor);
I get the following exception:
REFERENCED ITEM IS [class com.ibm.team.workitem.common.internal.model.impl.TimeSheetEntryHandleImpl]
com.ibm.team.repository.common.ItemNotFoundException: CRJAZ0215I The following record was not found in the database: com.ibm.team.workitem.common.internal.model.impl.TimeSheetEntryHandleImpl@1ee8c1 (stateId: <unset>, itemId: [UUID _cCrPAMprEeCtiMReqV6JAw], origin: com.ibm.team.repository.client.inte
rnal.TeamRepository@1bd523d, immutable: true)
at com.ibm.team.repository.client.internal.ItemManager.internalFetchItem(ItemManager.java:1602)
at com.ibm.team.repository.client.internal.ItemManager.access$1(ItemManager.java:1559)
at com.ibm.team.repository.client.internal.ItemManager$AbstractStore.retrieveItem(ItemManager.java:196)
at com.ibm.team.repository.client.internal.ItemManager$CurrentStore.fetchItem(ItemManager.java:321)
at com.ibm.team.repository.client.internal.ItemManager.fetchCompleteItem(ItemManager.java:845)
at com.ibm.ips.gui.rtc.RTC.retrieveAllUserWorkItems(com.ibm.ips.gui.rtc.RTC:822)
at com.ibm.ips.gui.threads.RTCRefreshThread.run(com.ibm.ips.gui.threads.RTCRefreshThread:190)
at java.lang.Thread.run(Thread.java:619)
One strange item of note is that if I create time sheet entries via the Eclipse client and query the references, I notice that they all have the same ItemId, yet, the createTimeSheetEntry line above creates a unique item id. Not sure if thats what the underlying problem is or not. Any help on this matter would be greatly appreciated, especially since the post here:
https://jazz.net/forums/viewtopic.php?t=18764
was never replied to :-(
Hi.
I'm trying to do the same thing, but with the Service API, using an OperationParticipant.
With the code bellow I don't get any errors and saves the workItem just fine, but it does not create a new TimeSheetEntry.
Does anyone have an idea?
ITimeSheetEntry newEntry = workItemService.createTimeSheetEntry(wiCopy.getProjectArea());
newEntry.setHoursSpent(hourInterval);
newEntry.setStartDate(alocationDate);
IWorkItemReferences references = workItemService.resolveWorkItemReferences(wiCopy, null);
IItemReference timesheetRef = IReferenceFactory.INSTANCE.createReferenceToItem(newEntry);
references.add(WorkItemEndPoints.WORK_TIME, timesheetRef);
workItemService.saveWorkItem2(wiCopy, references, null);
Thanks in advance.
Luana
I'm trying to do the same thing, but with the Service API, using an OperationParticipant.
With the code bellow I don't get any errors and saves the workItem just fine, but it does not create a new TimeSheetEntry.
Does anyone have an idea?
ITimeSheetEntry newEntry = workItemService.createTimeSheetEntry(wiCopy.getProjectArea());
newEntry.setHoursSpent(hourInterval);
newEntry.setStartDate(alocationDate);
IWorkItemReferences references = workItemService.resolveWorkItemReferences(wiCopy, null);
IItemReference timesheetRef = IReferenceFactory.INSTANCE.createReferenceToItem(newEntry);
references.add(WorkItemEndPoints.WORK_TIME, timesheetRef);
workItemService.saveWorkItem2(wiCopy, references, null);
Thanks in advance.
Luana
Looks like you are missing the same line of code that I was missing originally, the stuff around wc.getDependentItems().add(...). Not sure how to do that on the server side though.
Hi.
I'm trying to do the same thing, but with the Service API, using an OperationParticipant.
With the code bellow I don't get any errors and saves the workItem just fine, but it does not create a new TimeSheetEntry.
Does anyone have an idea?
ITimeSheetEntry newEntry = workItemService.createTimeSheetEntry(wiCopy.getProjectArea());
newEntry.setHoursSpent(hourInterval);
newEntry.setStartDate(alocationDate);
IWorkItemReferences references = workItemService.resolveWorkItemReferences(wiCopy, null);
IItemReference timesheetRef = IReferenceFactory.INSTANCE.createReferenceToItem(newEntry);
references.add(WorkItemEndPoints.WORK_TIME, timesheetRef);
workItemService.saveWorkItem2(wiCopy, references, null);
Thanks in advance.
Luana