It's all about the answers!

Ask a question

please help! cannot add/modify time sheets - ITimeSheetEntry


0
2
Aaron LaBella (5143) | asked Aug 19 '11, 10:39 a.m.
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 :-(

4 answers



permanent link
Aaron LaBella (5143) | answered Sep 15 '11, 4:10 p.m.
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!

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 :-(

permanent link
Luana Santos (1122) | answered Oct 06 '11, 12:36 p.m.
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

permanent link
Aaron LaBella (5143) | answered Oct 10 '11, 2:23 p.m.
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

permanent link
Luana Santos (1122) | answered Oct 11 '11, 12:47 p.m.
I tried to find a similar structure of the wc.getDependentItems() in the server side but I didn't have any success.

Comments
Nate Decker commented Apr 24 '15, 11:13 a.m.

Luana, I need to do this too. Did you ever find a solution? I likewise can't find a server-side equivalent for the code examples here on Jazz.net.

Your answer


Register or to post 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.