It's all about the answers!

Ask a question

How Do I Save Non-WorkItems via Server-Side Java API?

Nate Decker (37813959) | asked Apr 06 '15, 1:34 p.m.

I am working on developing a custom operation behavior follow-up action (Java server-side API).

I have successfully saved work items in the past by using the IWorkItemServer class. I now need to be able to save something that isn't a work item (specifically, an instance of a ITimeSheetEntry).

I thought to try and do this using the IRepositoryItemService. There is a "saveItem" function that looked promising. However, this function threw an exception with the message "Access violation in component item service."

Reading here on the forums, I found a statement by a Jazz developer that may explain this:

Save operations must be routed through the owning component's API, in this case through the work item API.

The Jazz developer was answering a question for someone on how to save Work items, so the answer doesn't really help me in my case (since I already know how to save work items) except to suggest that I can't do what I want to do via the IRepositoryItemService.

If each "component" has its own service, then I guess I just need to know what service to use for the ITimeSheetEntry item.

One answer

permanent link
Ralph Schoon (62.3k33643) | answered Apr 07 '15, 2:11 a.m.
I don't know if there is a related call in the server API. In the client API, what the adding dependent items does is in the code and looks as follows:

	SaveParameterDTO saveParameter= createSaveParameter(workingCopy);
	for (IAuditable auditable : workingCopy.getDependentItems().getAll()) {
		IAuditable copy= (IAuditable) EMFHelper.copy(auditable);
		SaveParameterDTO dependentParameter= Utils.createSaveParameter(copy, null, null, Collections.emptySet());

It basically creates special save parameters.

Nate Decker commented Apr 07 '15, 8:14 a.m.

Thanks for the suggestion, but I've tried that as well. Evidently, the timesheet entry doesn't get saved because it is a "working copy" and simply adding it to the work item's references doesn't flag it to be saved. When I navigate to the work item after the follow-up action triggers, I can get a clue when I click on the Time Tracking tab. A null pointer exception is displayed. I'm assuming this is happening because there is a link to a timesheet entry, but the timesheet entry doesn't exist (since it was not saved).

I suspect I need a way to explicitly tell RTC that the working copy timesheet entry is a dependent item of the work item. That's what I've seen in some examples of client-side code. However, I can't seem to find an equivalent server-side function for that. I haven't seen this "Utils" code before so maybe I can search for a server-side equivalent for that. Thanks for weighing in.

Ralph Schoon commented Apr 07 '15, 8:44 a.m.

Sorry, I couldn't find an obvious solution.

sam detweiler commented Apr 07 '15, 9:14 a.m.

 I think you would use IAuditableCommon.saveProcessItem() cause it hangs off the process area

Your answer

Register or to post your answer.