It's all about the answers!

Ask a question

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


Alexander Kershaw (1323) | asked Jul 03 '14, 9:49 a.m.
edited Jul 03 '14, 10:19 a.m. by Arne Bister (2.6k12632)
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

2 answers



permanent link
Stephen Hurst (1112) | answered Aug 26 '14, 11:25 a.m.
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

permanent link
Rosa Naranjo (2.8k11420) | answered Jul 03 '14, 11:52 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
 Alexander
The blog also contains other useful examples

Comments
Alexander Kershaw commented Jul 07 '14, 6:05 a.m.

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


Ralph Schoon commented Jul 07 '14, 7:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Alexander Kershaw commented Aug 06 '14, 6:33 a.m.

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


Ralph Schoon commented Aug 06 '14, 10:58 a.m. | edited Aug 06 '14, 10:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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 to post your answer.