It's all about the answers!

Ask a question

How to get WorkItem references from an IChange or IChangeset?

Andy Jewell (24225771) | asked Sep 10 '15, 4:39 p.m.
edited Sep 10 '15, 4:45 p.m.
Hi. . . There are numerous examples online and on the forum of getting references to IChangesets through the WorkItem/WorkItemCopy.  Most clearly, from Ralph's blog:

public List<IChangeSet> findChangesetsOnWorkItem(WorkItemWorkingCopy wc) throws RtcException, TeamRepositoryException{
   IWorkItemReferences references = wc.getReferences();
List<IReference> chgsetrefs = new ArrayList<IReference>();
   for (IEndPointDescriptor iEndPointDescriptor : references.getTypes()) {
           // blah
   // now resolve items
   List<IChangeSet> itemlist = null;
   try {
       itemlist = resolveChangesetReferences(chgsetrefs);
   } catch (TeamRepositoryException e) {
       throw new RtcException("Had a problem while resolving changeset references",e);
   return itemlist;

Also, in this RTC article (reference "Discovering Links Between Items") by Chris McGee.

However, these are examples of finding various links from a workitem.  Is there a way to find links from a changeset or from a change?  I have an IChangeset and I want to find all the work items that are linked to it.

Also, I don't see any reference in the 5.0.2 java API docs for IReference, ILink, or ILinkManager.  Does anyone know the reason for that?


Accepted answer

permanent link
Ralph Schoon (61.4k33643) | answered Sep 11 '15, 3:32 a.m.
edited Sep 11 '15, 3:35 a.m.
You are starting with a change set and not a work item. In that case this might be more appropriate:

Restrict Delivery of Changesets Associated to Wrong Work Item Types Advisor

Andy Jewell selected this answer as the correct answer

Andy Jewell commented Sep 14 '15, 1:08 p.m.

I missed that one!  Good article, thank you for sharing your work!

One other answer

permanent link
Andy Jewell (24225771) | answered Sep 14 '15, 1:10 p.m.
edited Sep 14 '15, 1:12 p.m.
This is what I did, based on code referenced in answer:

     * Get work item links from a changeset
     * @param chgset
     * @return
     * @throws TeamRepositoryException
    public Set<IWorkItemHandle>getWorkItemLinks(IChangeSetHandle chgset) throws TeamRepositoryException{         Set<IWorkItemHandle> wis = new TreeSet<IWorkItemHandle>();
        // Get the ProviderFactory to be able to find the links
        ProviderFactory pf = (ProviderFactory) repo.getClientLibrary(ProviderFactory.class);
        List<ILink> links = ChangeSetLinks.findLinks(pf,chgset,
                new String[] { ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID },
        for (ILink link : links) {
            Object resolved = link.getTargetRef().resolve();
            if (resolved instanceof IWorkItemHandle) {
                IWorkItemHandle wih = (IWorkItemHandle)resolved;
        return wis;

vijayakumar ramesh commented Jan 15 '21, 5:26 a.m. | edited Jan 15 '21, 5:26 a.m.

Thanks Andy Jewell, your code helped me 

Future Users can use below code along with above comment works for Client API 
IWorkItem workItem =  (IWorkItem) teamRepository.itemManager().fetchCompleteItem(wih, IItemManager.DEFAULT, monitor); 

Your answer

Register or to post your answer.