It's all about the answers!

Ask a question

Get children/links of work item combine Queries with Java Plain API


thanh nham (133) | asked May 19 '18, 1:54 a.m.
edited May 19 '18, 6:05 a.m.

I have an work item and I have to fetch all work items link to this work item ( Ex: have Parent and Contribute to), but I also need to filter links/children with queries (Ex:I use share query to fetch work items  type is defect and file against ABC)
_First, I can run findLinks() for this work item to get all the links/childrens
_Second, I can get list result by using Query ( or Expression)
=> My problem is I don't know how to combine 2 conditions.

Accepted answer


permanent link
Ulf Arne Bister (1.3k413) | answered May 20 '18, 11:13 a.m.

 Thanh,


please take a look at https://jazz.net/wiki/bin/view/Main/QueryDevGuide especially the section about constructing a term to combine filter expressions. If this helps please mark the answer resolved.

Term term= new Term(Operator.AND);
term.add(expressionOne);
term.add(expressionTwo);
    
...
IQueryResult<IResolvedResult<IWorkItem>> result= queryService.getResolvedExpressionResults(projectArea, term, profile);

thanh nham selected this answer as the correct answer

Comments
thanh nham commented May 20 '18, 11:24 p.m.

Thank Ulf for your answer, but it still not solve my problem
_First, as I know: the expression can not fetch links
_Second, I run a share query / personal query (IQueryDescriptor) to get the results ( not a Expression)

  • IQueryResult unresolvedResults = queryClient.getQueryResults(query)
            



Ulf Arne Bister commented May 21 '18, 4:08 p.m. | edited May 21 '18, 4:09 p.m.

So you run a shared query and want to get the intersection of those results with the list of children work items of a particular story?

In that case it becomes a simple java exercise:
1. write a method to find the intersection of two lists
2. convert your IQueryResult to List (.toList() ) of type <IWorkItemHandle>
3. If your original IQueryResult had a lot of results you might have to loop over until all pages have been loaded
4. write code to retrieve the children of the story as IWorkItemHandle list
(Ralph Schoon has a good article on this, look for the section with "Accessing references: https://rsjazz.wordpress.com/2012/09/19/the-rtc-workitem-link-api-linking-workitems-to-other-elements/ )
5. use method from 1. to get intersection of both Lists --> this should be the result you were looking for



thanh nham commented May 22 '18, 11:09 a.m.

Thank Ulf.

I think there is only solution is using java code to intersect 2 list like you said.
Actually, I had though about that. But I have to get children (n1) combine query-1 of a list parent (p), then find children (n2) combine query-2 of n1. And I fear that java code will slow the performance, so I ask for a combine query (if it is possible).

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.