It's all about the answers!

Ask a question

Query RTC work items with a certain tag programmatically


Marko Tomljenovic (3164197) | asked Mar 09 '16, 9:35 a.m.
I am trying to create and run a query in order to find all work items in a specific project area that has a specific tag.

For that I am using the following code:

    ITeamRepository repo = (ITeamRepository) prjArea.getOrigin();
    IAuditableCommon auditableCommon = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class);
    IQueryableAttributeFactory factory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);

    IQueryableAttribute attributeTags =
        factory.findAttribute(prjArea, IWorkItem.TAGS_PROPERTY, auditableCommon, monitor);

    Expression hasTag = new AttributeExpression(attributeTags, AttributeOperation.CONTAINS, TAG_NAME);

    Term term = new Term(Operator.AND);
    term.add(hasTag);

    IQueryClient queryClient = (IQueryClient) repo.getClientLibrary(IQueryClient.class);
    IQueryResult<IResolvedResult<IWorkItem>> queryResult =
        queryClient.getResolvedExpressionResults(prjArea, term, IWorkItem.FULL_PROFILE);

    List<IWorkItem> workItems = new ArrayList<IWorkItem>(queryResult.getResultSize(monitor).getTotalAvailable());


The resulting list is empty although it should return one work item. (I tested with a manually created query).

What am I missing here?

Thank you


One answer



permanent link
Marko Tomljenovic (3164197) | answered Mar 09 '16, 11:35 a.m.
I missed that part of code.

    while (queryResult.hasNext(monitor)) {
      if (monitor.isCanceled()) {
        return null;
      }
      IResolvedResult<IWorkItem> resolvedResult = queryResult.next(monitor);
      IWorkItem workItem = resolvedResult.getItem();
      workItems.add(workItem);
    }

Your answer


Register or to post your answer.