It's all about the answers!

Ask a question

[plain java] Adding Work Item type to query?


Bryan Miller - Integration Developer (4493431) | asked Jun 18 '12, 3:54 p.m.
retagged Nov 13 '12, 4:02 a.m. by Morten Madsen (3052842)
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.

2 answers



permanent link
Dinesh Kumar B (4.0k413) | answered Jun 19 '12, 3:08 a.m.
JAZZ DEVELOPER
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);

Comments
Bryan Miller - Integration Developer commented Jun 19 '12, 9:59 a.m.

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?


permanent link
Gabriel Enriquez (3313) | answered Jun 19 '12, 1:05 p.m.
JAZZ DEVELOPER
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

Comments
Bryan Miller - Integration Developer commented Jun 19 '12, 1:26 p.m.

Much obliged Gabriel. I had the correct code but was capitalising "defect" as "Defect" and that apparently doesn't match anything...


Morten Madsen commented Nov 13 '12, 3:58 a.m.

Hi Gabriel, do you have a link to this "Developer's Guide" ....?


Gabriel Enriquez commented Nov 13 '12, 1:03 p.m.
JAZZ DEVELOPER

Here is a link to the Query Dev Guide.

Your answer


Register or to post your answer.