2

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);
Rinkal Garg
  • 173
  • 9
  • Would a simple getId() be enough? (as shown in https://rsjazz.wordpress.com/2012/09/20/the-rtc-workitem-server-link-api-linking-to-work-items-and-other-elements/, in the code just after the sentence "In case the other end is a work item it uses the location information to get the work item.") – VonC Mar 20 '18 at 08:08
  • @VonC we can't cast link into work item. – Rinkal Garg Mar 20 '18 at 09:41
  • Could you resolve the link though? To a WorkItem? As in https://jazz.net/forum/questions/174327/how-to-get-work-item-owner-name-from-rtc-plain-java-api#comment-174404 – VonC Mar 20 '18 at 09:43
  • @VonC This code is not returning the child or parent work item id. – Rinkal Garg Mar 20 '18 at 10:10
  • Agreed. I didn't meant for you to reuse that code as is. Just see of, from your own code (which has a collection of ILink) you can resolve said ILink to a Work Item from which you can get the Id. – VonC Mar 20 '18 at 10:11
  • @VonC Thank you so much for your help, I am able to get the work item id. Really appreciating your efforts. Thanks a ton :) – Rinkal Garg Mar 20 '18 at 10:49
  • Great, I will add an answer later today – VonC Mar 20 '18 at 10:51

1 Answers1

0
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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • can you please help me on this question too. https://stackoverflow.com/questions/49399464/how-to-find-work-item-filed-against-category-value-using-plain-java-api – Rinkal Garg Mar 21 '18 at 06:22