It's all about the answers!

Ask a question

Querying Work Items based on IWorkItemType


Sivasamy Sethupathi (1632) | asked Oct 12 '09, 1:43 a.m.
Hi,

I want to query the Work items based on certain work item types along with other conditions. Since more than one workitem types I want to check, I used AttributeOperation.MATCHES in the expression and it doesn't seem to work. At the same time, if I use AttributeOperation.EQUALS, it works. I understand matches operation internally does an equals operation on every object in the supplied Collection. Given below is the code snippet.


IQueryableAttribute workItemTypeAttribute = factory.findAttribute(
projectArea, IWorkItem.TYPE_PROPERTY, getAuditableClient(),
monitor);

// This returns all 'task' type workitems.
AttributeExpression workItemTypeExpression = new AttributeExpression(
workItemTypeAttribute, AttributeOperation.EQUALS, "task");

// This doesn't return any workitems.
List<String> workItemTypes = new ArrayList<String>();
workItemTypes.add("task");
workItemTypes.add("defect");
AttributeExpression workItemTypeExpression = new AttributeExpression(
workItemTypeAttribute, AttributeOperation.MATCHES, workItemTypes);


Please correct me if I'm wrong and help me out.

Thanks and regards,
Sethu

2 answers



permanent link
Patrick Streule (4.9k21) | answered Oct 12 '09, 3:58 a.m.
JAZZ DEVELOPER
// This doesn't return any workitems.
List<String> workItemTypes = new
ArrayList<String>();
workItemTypes.add("task");
workItemTypes.add("defect");
AttributeExpression workItemTypeExpression = new
AttributeExpression(
workItemTypeAttribute, AttributeOperation.MATCHES,
workItemTypes);

MATCHES is the same as EQUALS and exists only for backward compatibility
reasons.

Your statement looks ok to me (although using EQUALS would be recommended).

Alternatively, you can OR the different values explicitly:

AttributeExpression defectExpression = new
AttributeExpression(workItemTypeAttribute, AttributeOperation.EQUALS,
"defect");
AttributeExpression taskExpression = new
AttributeExpression(workItemTypeAttribute, AttributeOperation.EQUALS,
"task");

Term term= new Term(Operator.OR);
term.add(defectExpression);
term.add(taskExpression);

--
Regards,
Patrick
Jazz Work Item Team

permanent link
Sivasamy Sethupathi (1632) | answered Oct 12 '09, 7:27 a.m.
Thanks very much Patrick.

Since my workitem types are known only at run time, I'm creating and adding attribute expressions to an OR Term in a loop. It works.

Regards,
Sethu

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.