I want to remove "ContributesTo" link values programmatically depending on the values in affected app workitem attribute.
I had used LinkServiceLibrary approach to create "ContributesTo" link programatically for each value in the affected app workitem attribute. No I want to implement the removal functionality whenever I remove a workitem value from the affected app workitem attribute ,I want it to be automatically removed from the "ContributesTo" Link. The method for removal is as follows:
private void removeContributesToLink(IWorkItem sourceWorkItem,
List<Integer> affectedWorkItems, IWorkItemServer workItemServer)
throws TeamRepositoryException {
IWorkItemReferences resolveWorkItemReferences = workItemServer.resolveWorkItemReferences(sourceWorkItem, null);
IEndPointDescriptor tracksEndpoint = ILinkTypeRegistry.INSTANCE
.getLinkType(WorkItemLinkTypes.CONTRIBUTES_TO_WORK_ITEM)
.getTargetEndPointDescriptor();
List<IReference> references2 = resolveWorkItemReferences
.getReferences(tracksEndpoint);
for (IReference link : references2) {
IWorkItemHandle resolve = (IWorkItemHandle) link.resolve();
IWorkItem appWI = workItemServer.getAuditableCommon()
.resolveAuditable(resolve, IWorkItem.FULL_PROFILE, null);
if (!affectedWorkItems.contains(appWI.getId())) {
resolveWorkItemReferences.remove(link);
}
}
Set additionalParams = new HashSet();
additionalParams
.add(IAdditionalSaveParameters.IGNORE_BACKLINK_PROBLEMS);
workItemServer.saveWorkItem3(sourceWorkItem, resolveWorkItemReferences,
null, additionalParams);
}
But I am getting Stale Data Exception when running the code. Can you please give some insights on this issue. Is there any other methods to remove links from a workitem using LinkServiceLibrary??
One answer
Why would you run this on the server?
All posts are tagged and searchable.
You can fetch/resolve the sourceWorkItem immediately before saving it. This usually worked for me.