Querying Work Items based on IWorkItemType
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.
Please correct me if I'm wrong and help me out.
Thanks and regards,
Sethu
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
// 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