It's all about the answers!

Ask a question

Fetching WorkItems based on some text on URI of Related Artifacts using plain java API

Sridhar Kuna (1602017) | asked Aug 27 '15, 11:03 a.m.
edited Aug 28 '15, 4:59 a.m.
We want to retrieve workItems based on some text (eg: ibm) from 'Related artifacts' (which is really standard html link, eg URI: attached as Links in the Links tab. Any help would be really appreciated?

2 answers

permanent link
sam detweiler (12.5k6195201) | answered Aug 28 '15, 5:27 a.m.
You can create a workitem query that will return workitems that HAVE Related Artifact links.
then you can examine each workitem..

I provided a sample that will dump out all workitems returned in a query, the accepted answer here.

after you get that to work, you can add code to create the query dynamically.
see Ralphs blog

permanent link
Sridhar Kuna (1602017) | answered Sep 02 '15, 11:16 a.m.
Thanks sam for your quick reply. I have not tried using workitem query. But worked for me as below,

//First get the required workitems and on each workitem do some logic based on "Related artifact" link defined.
-----------------------------------------<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.FULL_PROFILE);

while (results.hasNext(monitor)) {
  IResolvedResult<IWorkItem> workitemResult = (IResolvedResult<IWorkItem>);
  IWorkItem workItem = workitemResult.getItem();
  ILinkManager linkManager = (ILinkManager)      teamRepository.getClientLibrary(ILinkManager.class);
  workItemReference =  linkManager.referenceFactory().createReferenceToItem(workItem);

linkQueryPage = linkManager.findLinksBySource(WorkItemLinkTypes.RELATED_ARTIFACT, workItemReference, monitor);
linkCollection = linkQueryPage.getAllLinksFromHereOn();

for (ILink l : linkCollection) {
    System.out.println("URL: " + l.getTargetRef().createURI()+ ", Comment: " + l.getTargetRef().getComment());
    if (l.getTargetRef().createURI().toString().contains("some string that you would be searching as part of URI"))
    //Once you determined that WorkItem with specific URI string
   //DO your logic

Your answer

Register or to post your answer.