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

Adding a 'related change request' between work items using the RTC Java API

I have the IWorkItemHandle object of 2 work items on different servers. How do I then add a 'related change request' link between them?

Thanks,
Alex

0 votes



2 answers

Permanent link
Hi Alex,

This is very much psuedo-code, but hopefully will give you enough pointers to work with the RTC API to achieve what you would like to do. You say you have your handles already, so in this example:
IWorkItemHandle localHandle; 
IWorkItemHandle remoteHandle; 
First up, you need a link manager:
public ILinkManager linkManager  = (ILinkManager) getTeamRepository().getClientLibrary(ILinkManager.class);
	

The link manager is used to update the links on the localHandle to the remoteHandle. Next create a pair of localRef and remoteRef references using the link manager:

IItemReference localRef = linkManager.referenceFactory().createReferenceToItem(localHandle);
java.net.URI uri = new URI(remoteRtcServerAddress+"/resource/itemName/com.ibm.team.workitem.WorkItem/"+remoteWorkItemId);
IURIReference remoteRef = linkManager.referenceFactory().createReferenceFromURI(uri, "Link to remote repository");

Then create and save the link:

ILink link = linkManager.createLink("com.ibm.team.workitem.linktype.relatedartifact", localRef, remoteRef);
linkManager.saveLink(link, null);

Hope that helps.
Cheers, Steve

1 vote


Permanent link
 Alexander
The blog also contains other useful examples

0 votes

Comments

Hi Rosa,

I can't seem to get it to work using that article.

I have 2 different work items and their respective RTC repositories and all of the usual values for them (e.g. workItemHandle1, workItemHandle2, workingCopy1, workingCopy2, etc).

Using IReferenceFactory.INSTANCE.createReferenceToItem on the IWorkItemHandles, I can get IItemReferences, i.e. reference1 and reference2.

I'm using WorkItemLinkTypes.RELATED_CHANGE_MANAGEMENT as the link as I assume this is the correct one for 'related change request' - let's call this linkStr.

Using the above values, I've tried 2 approaches:

1)  Use ILinkFactory.INSTANCE.createLink(linkStr, reference1, reference2) followed by ((ILinkManager) repository1.getClientLibrary(ILinkManager.class)).saveLink(link, monitor1)

2) Getting an endPoint via ILinkTypeRegistry.INSTANCE.getLinkType(linkStr).getTargetEndPointDescriptor() then using workItemWorkingCopy2.getReferences().add(endPoint, reference1)

Neither approach works. Any ideas?

Thanks

All I can suggest is to look at existing links to try to figure out how they should look like- that is what I have to do if I are bold enough to look at a new API. I would hope https://rsjazz.wordpress.com/2012/09/19/the-rtc-workitem-link-api-linking-workitems-to-other-elements/ should provide you with the right information. It is important to find out what the link type is. I would start here: https://rsjazz.wordpress.com/2012/11/01/restrict-delivery-of-changesets-to-workitem-types-advisordelivery-of-changesets-associated-to-wrong-work-item-types-advisor/ . That uses ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID. Please be aware that there is also SCM API involved somehow. I am not sure what your link type represents.

Hi Ralph - I've tried replacing both of my potential solutions (from my previous comment) with ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID as the id and it still doesn't work. I can't find any other suggestions in the links you've posted.

Cheers,
Alex

I can't help a lot here. If the link is between items in different repositories, then they are CLM links. CLM links are created in a different way. I have some hints here: http://rsjazz.wordpress.com/2013/11/06/creating-clm-links-with-back-link/

I have only tried to create tracks links between work items in one repository, so I can't answer how that works across repositories. 

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,941
× 369
× 49

Question asked: Jul 03 '14, 9:49 a.m.

Question was seen: 6,528 times

Last updated: Aug 26 '14, 11:25 a.m.

Confirmation Cancel Confirm