[plain java] Adding Work Item type to query?
I have a Work Item query that works well but I wish to add an expression to my existing query to filter by Work Item type (defect, task, etc). I am not seeing any methods that will take my type string (i.e. "Defect") and return a type ID to add to my existing query.
Any thoughts? BTW, I have read the excellent Developer's Guide to Querying Work Items and it doesn't cover this use case.
Any thoughts? BTW, I have read the excellent Developer's Guide to Querying Work Items and it doesn't cover this use case.
2 answers
here is something that i use, key is to get a queryable reference to the workitem type property and compare it with the specific workitem type ID.
//Create the Term
Term queryTerm = new Term(Operator.AND);
//work item type ID to be used to filter
var mWorkitemType = "workitemtypeID";
// gather a queryable reference to the Workitem Type property for this ProjectArea
IQueryableAttribute workItemTypeAttribute = factory.findAttribute(mProjectArea, IWorkItem.TYPE_PROPERTY, mAuditableClient, mMonitor);
//build the attribute expression using the queryable reference to type property and the filter workitemtype ID
AttributeExpression exprnWorkItemType = new AttributeExpression(workItemTypeAttribute, AttributeOperation.EQUALS, mWorkitemtype);
// add the expression to your query term
queryTerm.add(exprnWorkItemType);
// run the query and capture the results
IQueryResult<IResolvedResult<IWorkItem>> queryResult =
mQueryClient.getResolvedExpressionResults(mProjectArea, queryTerm, IWorkItem.FULL_PROFILE);
//Create the Term
Term queryTerm = new Term(Operator.AND);
//work item type ID to be used to filter
var mWorkitemType = "workitemtypeID";
// gather a queryable reference to the Workitem Type property for this ProjectArea
IQueryableAttribute workItemTypeAttribute = factory.findAttribute(mProjectArea, IWorkItem.TYPE_PROPERTY, mAuditableClient, mMonitor);
//build the attribute expression using the queryable reference to type property and the filter workitemtype ID
AttributeExpression exprnWorkItemType = new AttributeExpression(workItemTypeAttribute, AttributeOperation.EQUALS, mWorkitemtype);
// add the expression to your query term
queryTerm.add(exprnWorkItemType);
// run the query and capture the results
IQueryResult<IResolvedResult<IWorkItem>> queryResult =
mQueryClient.getResolvedExpressionResults(mProjectArea, queryTerm, IWorkItem.FULL_PROFILE);
Comments
Thank you Dinesh. I may not have asked the question as clearly as I should have.
I am trying to figure out how to get the contents of workitemtypeID from a display value (e.g. Defect). Is there a method call (or series of method calls more likely) which will take a string display value (.e.g Defect) and return an type ID for that project?
Use the ID from the process configuration Work Item Type editor as String. For instance, for a defect:
//following the code from "Developer's Guide to Querying Work Items"...
new AttributeExpression(
findAttribute(projectArea, auditableClient, IWorkItem.TYPE_PROPERTY, null),
AttributeOperation.EQUALS,
"defect"
);
--
Gabriel Enriquez, IBM Rational, Tracking & Planning
//following the code from "Developer's Guide to Querying Work Items"...
new AttributeExpression(
findAttribute(projectArea, auditableClient, IWorkItem.TYPE_PROPERTY, null),
AttributeOperation.EQUALS,
"defect"
);
--
Gabriel Enriquez, IBM Rational, Tracking & Planning
Comments
Much obliged Gabriel. I had the correct code but was capitalising "defect" as "Defect" and that apparently doesn't match anything...
Hi Gabriel, do you have a link to this "Developer's Guide" ....?
Here is a link to the Query Dev Guide.