Adding a 'related change request' between work items using the RTC Java API
2 answers
IWorkItemHandle localHandle;
IWorkItemHandle remoteHandle;
public ILinkManager linkManager = (ILinkManager) getTeamRepository().getClientLibrary(ILinkManager.class);
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");
ILink link = linkManager.createLink("com.ibm.team.workitem.linktype.relatedartifact", localRef, remoteRef);
linkManager.saveLink(link, null);
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.