javaapirtcworkitem

How to get work item Id using link source Reference?


I am using the below code to fetch parent and children of the work item and I got link reference, Now I want to fetch the work item Id from object. Please help

IReference reference = linkManager.referenceFactory().createReferenceToItem(workItem 
                               .getItemHandle()); 
                               ILinkQueryPage page; 
                               ILinkQueryPage page1; 

                               page = linkManager.findLinksByTarget("com.ibm.team.workitem.linktype.parentworkitem", reference, monitor); 

                               ILinkCollection linkCollection = page.getLinks(); 


                               Collection childWI = linkCollection.getLinksById("com.ibm.team.workitem.linktype.parentworkitem");

                               System.out.println(childWI);

Solution

  • ILinkCollection linkCollection = page.getLinks(); 
    Collection childWI = linkCollection.getLinksById(...)
    

    That means you have a collection of ILink(s).

    As seen here, it is easy to resolve a link to a WorkItem:

    for (ILink l : links) {
        IItemHandle linkHandle = (IItemHandle) l.getTargetRef().resolve();
        if (linkHandle instanceof IWorkItemHandle) {
            IWorkItem aWorkItem = (IWorkItem) teamRepository.itemManager().fetchCompleteItem(linkHandle, IItemManager.DEFAULT, monitor);
        }
    }
    

    Each WorkItem has a getId() method to access its ID.