Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

[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.

0 votes



2 answers

Permanent link
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);

2 votes

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?


Permanent link
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

2 votes

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.

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952

Question asked: Jun 18 '12, 3:54 p.m.

Question was seen: 6,613 times

Last updated: Nov 13 '12, 1:03 p.m.

Confirmation Cancel Confirm