Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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??

0 votes



One answer

Permanent link

 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.

0 votes

Comments

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

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Mar 22, 1:58 a.m.

Question was seen: 706 times

Last updated: Mar 22, 3:44 a.m.

Confirmation Cancel Confirm