How to force a Save operation when only changing links in a work item using java plain client?
Accepted answer
- This here describes how you operate with work item: https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation . The best way to update a work item is to use a work item operation as in the examples.
- I am not sure what ILinkManager does, but it does not save links on a work item.
- The code below is used to add a new link to the work items references the implementation uses a work item operation. If you use other methods make sure to use the work item save method that also saves the references. A working copy only has saver(monitor) the Server API has other save2 and save 3 and only the latter saves the references.
// Linking Blocking private static class LinkBlockingWorkItemOperation extends WorkItemOperation { private IWorkItemHandle fOpposite; public LinkBlockingWorkItemOperation(IWorkItemHandle opposite) { super("Linking Blocking Work Item", IWorkItem.FULL_PROFILE); fOpposite = opposite; } @Override protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException { IItemReference reference = IReferenceFactory.INSTANCE .createReferenceToItem(fOpposite); workingCopy.getReferences().add(WorkItemEndPoints.BLOCKS_WORK_ITEM, reference); } }
Comments
Please also note, that the operation behavior is only triggered for work item links (like parent/child) but not for CLM links that work across servers e.g. Tracks/Contributes to.
Thank you Ralph. I am using the WorkItemOperation way of updating the work item. It was inside the execute() method here where I had the code to update a work item attribute value, AND used the ILinkManager to remove/add the link. I believe you're right in that this does not directly do things through the work item itself. I'll play with trying to modify the links on a work item through the work item references as you suggest.
You might also have to add:
Thank you Ralph. You were correct in my scenario that I needed to use the work item's references (workingCopy.getReferences()) for removing and adding the parent link instead of using ILinkManager. This solution causes a perceived change on the work item itself, which then kicks off all my preconditions and followup actions, which is the behavior I wanted. Got it working now.
1 vote