It's all about the answers!

Ask a question

I want to remove "ContributesTo" link values programmatically depending on the values in affected app workitem attribute.


Chaithra Komath (111) | asked Mar 22, 1:58 a.m.

 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



permanent link
Ralph Schoon (63.6k33647) | answered Mar 22, 3:11 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 Why would you run this on the server? 

In general, I have provided some examples here: https://rsjazz.wordpress.com/ 
All posts are tagged and searchable.

You can fetch/resolve the sourceWorkItem immediately before saving it. This usually worked for me.


Comments
Ralph Schoon commented Mar 22, 3:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You would probably also want to update/remove the backlinks, if there are any.  

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.