How Do I Save Non-WorkItems via Server-Side Java API?
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
SaveParameterDTO saveParameter= createSaveParameter(workingCopy); saveParameter.getAttachments().addAll(attachments); saveParameters.add(saveParameter); for (IAuditable auditable : workingCopy.getDependentItems().getAll()) { IAuditable copy= (IAuditable) EMFHelper.copy(auditable); SaveParameterDTO dependentParameter= Utils.createSaveParameter(copy, null, null, Collections.emptySet()); dependentParameters.add(dependentParameter); }
It basically creates special save parameters.
Comments
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.
Sorry, I couldn't find an obvious solution.
I think you would use IAuditableCommon.saveProcessItem() cause it hangs off the process area