It's all about the answers!

Ask a question

Query for work items in just one ProjectArea


Andy Berner (61127) | asked Jun 12 '08, 11:56 a.m.
I have code to query for work items in a particular project area, but it's returning work items in ALL the project areas in the repository (or maybe it's in my workspace--for now those are the same). The method takes the IProjectArea as a parameter, so I'm surprised that it doesn't limit the results to that project. What's the right code to get just the work items in a single project?

Here's my current code. The important line (I think) is the last line just before the return that does the query and passes the IProjectArea:

private IQueryResult<IResolvedResult<IWorkItem>> findWorkItemsByType(ITeamRepository repo,
IProjectArea project,
String typeName,
ItemProfile<IWorkItem> theProfile)
throws TeamRepositoryException {
//get needed libraries
IQueryClient queryClient = (IQueryClient) repo.getClientLibrary(IQueryClient.class);
IAuditableClient auditableClient = (IAuditableClient) repo.getClientLibrary(IAuditableClient.class);
IQueryableAttributeFactory attFactory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
IQueryableAttribute typeAttribute =
attFactory.findAttribute(project, IWorkItem.TYPE_PROPERTY, auditableClient, null);
Expression expression= new AttributeExpression(typeAttribute, AttributeOperation.EQUALS, typeName);
IQueryResult<IResolvedResult<IWorkItem>> result = queryClient.getResolvedExpressionResults(project,
expression, theProfile);
return result;
}

2 answers



permanent link
Patrick Streule (4.9k21) | answered Jun 13 '08, 3:48 a.m.
JAZZ DEVELOPER
I have code to query for work items in a particular project area, but
it's returning work items in ALL the project areas in the repository
(or maybe it's in my workspace--for now those are the same). The
method takes the IProjectArea as a parameter, so I'm surprised that
it doesn't limit the results to that project. What's the right code
to get just the work items in a single project?

The project area condition is not automatically added. While this API is
typically used for work item queries, it is not fundamentally limited to
work items, so the correct project area attribute (if there is any) is
not known automatically.

To restrict the results, add a project area condition:

....
Expression expression= new AttributeExpression(typeAttribute,
AttributeOperation.EQUALS, typeName);

IQueryableAttribute projectAreaAttribute= findAttribute(projectArea,
IWorkItem.PROJECT_AREA_PROPERTY, monitor);
AttributeExpression projectAreaExpression= new
AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS,
projectArea);

Term term= new Term(Operator.AND);
term.add(projectAreaExpression);
term.add(expression);

You may be interested in some new documentation that is available on the
Wiki: https://jazz.net/wiki/bin/view/Main/QueryDevGuide
It is still a draft, but you may find it useful already.

Regards,
Patrick,
Jazz Work Item Team

permanent link
Marcos Vieira (611) | answered May 19 '11, 10:02 a.m.
Hi all.

How much custom attributes could I create by work item or project area?
Thanks.

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.