It's all about the answers!

Ask a question

how can be created a work item query with a team area property using the Java API?

Krasimir Malchev (56115) | asked Feb 14 '17, 10:53 a.m.

It is possible to create a work item query with a specified team area in the RTC Eclipse and web clients?

How can I create a similar one using the Plain Java API?

3 answers

permanent link
Kevin Ramer (4.4k6166186) | answered Feb 14 '17, 3:42 p.m.

You need to determing Category to Team/Project Area.   Assigning the work item category implicitly associates the work item to a process area ( Team or Project ). The attribute is exposed as Filed Against, but underneath it is the category.

This little snippet might help you see how the categories can be gotten from project area:

                IWorkItemClient service = getWorkItemClient();  // "private" method to my Jazz client class.   Your work probably already can do this.
                List<ICategory> findCategories=null;
                try {
// jazzServer.getProjectArea() returns an IProjectArea, you might have it another way.
                    findCategories = service.findCategories(
                            jazzServer.getProjectArea(), ICategory.FULL_PROFILE,
                } catch (TeamRepositoryException e) {
                    // TODO Auto-generated catch block
                for (ICategory category : findCategories) {
                    if (!category_cache.containsKey(category.getHierarchicalName())) {

                        logger.debug("Adding category name "+category.getHierarchicalName()+" to cache.");
                        category_cache.put(category.getHierarchicalName(), category);

The ICategory object has methods to get the associated process area, but the query should use the category.

Ralph Schoon commented Feb 15 '17, 3:53 a.m.

 Right, the TeamArea Property is not an attribute. as opposed to It is derived by using the category and you will likely have to get the categories from the team area and then search for the categories that are relevant.

I don't have an example. I can't possibly create examples for all the questions out there. I can only provide basic examples. You have to improve on that. 

permanent link
Ralph Schoon (57.7k23642) | answered Feb 14 '17, 11:07 a.m.

Krasimir Malchev commented Feb 14 '17, 11:13 a.m.

Yes, I have gone through these wonderful articles.

Though, I am still not able to specify a team area as a queryable attribute as it looks like the team area is not an attribute.
I want to create a query which returns all work items assigned to a specified team area or its child team areas.
I tried to use constructs like this:
if(processArea instanceof ITeamArea) {
   IAssociation association=   
Unfortunately it does not work.
Ralf, is it possible to help me what exactly should I do to get the result?

Thanks a lot!
K. Malchev

permanent link
Krasimir Malchev (56115) | answered Feb 15 '17, 6:04 a.m.
edited Feb 15 '17, 6:10 a.m.

@ Kevin Ramer: Thanks for the useful hint!

I have finally managed to solve my issue with the following pseudo-code:

   private void printQueryResults(IProcessArea fProcessArea,
IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItemCommon workItemCommonService = (IWorkItemCommon) teamRepository
IQueryCommon queryCommon = (IQueryCommon) teamRepository
IQueryableAttributeFactory attrFactory = QueryableAttributes
IQueryableAttribute attribProjectArea = attrFactory.findAttribute(
fProcessArea.getProjectArea(), IWorkItem.PROJECT_AREA_PROPERTY,
queryCommon.getAuditableCommon(), monitor);
Term workItemsInProcessArea = new Term(Term.Operator.AND);
Expression inProjectArea = new AttributeExpression(attribProjectArea,
AttributeOperation.EQUALS, fProcessArea.getProjectArea());
Term term = generateCategoryTerm(fProcessArea, workItemCommonService,
IQueryDescriptor descriptor = queryCommon.createQuery(
fProcessArea.getProjectArea(), "WorkItemsInProcessArea",
"WorkItemsInProcessArea", workItemsInProcessArea);
IQueryResult<IResolvedResult<IWorkItem>> resolvedResults = queryCommon
.getResolvedQueryResults(descriptor, IWorkItem.SMALL_PROFILE);
processResolvedResults(resolvedResults, monitor);
private static Term generateCategoryTerm(
IProcessArea processArea, IWorkItemCommon workItemCommonService,
IProgressMonitor monitor) throws TeamRepositoryException {
List<ICategory> processAreaCategories = workItemCommonService
ICategory.FULL_PROFILE, monitor);
Term processAreaCategoriesTerm = new Term(Operator.OR);
IQueryableAttribute categoryAttribute = QueryableAttributes.getFactory(
processArea.getProjectArea(), IWorkItem.CATEGORY_PROPERTY,
workItemCommonService.getAuditableCommon(), monitor);
for (ICategory category : processAreaCategories) {
Expression categoryExpression = new AttributeExpression(
categoryAttribute, AttributeOperation.EQUALS, category);
return processAreaCategoriesTerm;
private static void processResolvedResults(
IQueryResult<IResolvedResult<IWorkItem>> resolvedResults,
IProgressMonitor monitor) throws TeamRepositoryException {
long processed = 0;
while (resolvedResults.hasNext(monitor)) {
IResolvedResult<IWorkItem> result =;
IWorkItem workItem = (IWorkItem) result.getItem();
System.out.println("Processed work items: " + processed);

Your answer

Register or to post your answer.