Use Server-Side Java API to Create/Modify Timesheet Entries (ITimeSheetEntry)
![]() I have found several examples on these forums of how to programmatically create a Timesheet entry using the Java API. However, all of the examples that I've seen (including the Wiki) are for client-side java. I need to get this working for server-side Java, but have been unsuccessful. It seems like I am almost there. When the code executes, it seems to create a phantom link to a timesheet that doesn't actually exist. After I visit a work item where this follow-up action was triggered, I get a java.lang.NullPointerException from the eclipse interface complaining that the target item doesn't exist. So it seems like the timesheet entry that I create, is destroyed or lost when the follow-up action terminates. Here is the code:
There's a lot of code there, but I include it all for context. Here's the relevant part I think:
This method has been successful for me in the past in linking work items. However, most of the examples that I've seen seem to suggest I should be using an approach like this:
I haven't used this second approach because I've never been able to get it to work for saving links between work items. I've tried it here for Timesheet entries anyway, but it didn't seem to work here either. The examples that I've seen seem to emphasize the importance of a command like:
However, that command doesn't seem to be available in the same way in a server-side extension. I'd appreciate any help anyone can offer. |
One answer
![]()
Ralph Schoon (62.3k●3●36●43)
| answered Apr 07 '15, 2:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I don't know about the dependent items. See https://jazz.net/forum/questions/178015/how-do-i-save-non-workitems-via-server-side-java-api for what I know.
In the code above, if you create a reference, you have to add the reference to saveWorItem3 as a parameter to get them saved. IStatus saveStatus = fWorkItemServer.saveWorkItem3(workItem, references, workFlowAction, additionalParams); Comments I've tried multiple permutations of the above code and including the references in the save operation was one of them. That didn't seem to do the trick. I elaborate on the other post to which you linked in your response. Note that I think the approach above doesn't technically even need a workitem operation save. The helper function "LinkItemsWithoutPreconditions" saves the links without touching the work items. I've used it before to create links without triggering a Workitem save operation. I actually found it from one of your blog posts. You advised against using it because it didn't trigger an operation behavior, but in my case that's actually what I wanted. Even though it wasn't needed, I tried it anyway with and without the references. Nate,
You can, I believe, use the ILinkService to create links between items without having to save the items. Trouble is, that also does not surface in operational behavior.
I don't see where you save the ITimesheet entry, so the link would be lost
ITimeSheetEntry entry = service.createTimeSheetEntry(UpdateWorkItem.getProjectArea());
create is in memory.
Sam and Ralph, that's exactly my problem. The timesheet is created in memory, but never saved. In the client examples, the save happens by extension of saving the work item because the timesheet is added to the work item's list of dependent items. However, in the server-side API there doesn't seem to be an equivalent mechanism where you can flag the Timesheet Entry as a dependency. If that mechanism doesn't exist, I need to be able to explicitly save the timesheet entry some other way. I've been unable to find any save mechanism though. This is a frustrating problem because it seems really counter-intuitive that you could do something with a client API that isn't possible in a server API. I would think the server-API would be the more powerful and capable mechanism. looking at the code for WorkItemWorkingCopyManager in the sdk,
showing 5 of 6
show 1 more comments
|