How to query work items using Approvals with the API?
I am trying to use the API to implement work item retrieval based on Approval and other Quick Information types, such as links. However, I am not sure how to go about it.
I am aware of using IQueryableAttribute ,AttributeExpression for querying using work item attributes. But I do not know how to start with Approvals or other link types such as "Mentions".
One answer
So I found a way to do this using the QueryModel API.Basically,I do this:
BaseWorkItemQueryModel workItems = BaseWorkItemQueryModel.WorkItemQueryModel.ROOT;
IStringField state = workItems.internalApprovals().stateIdentifier();
IPredicate pred = state._like("Approved");
IItemQuery query = IItemQuery.FACTORY.newInstance((IItemQueryModel) workItems);
query.filter(pred);
Then you have to get an instance of TeamRepository and use it as follows
IQueryPage qpage = rep.getQueryService().queryItems(query, IQueryService.EMPTY_PARAMETERS, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE);
where rep is of type TeamRepository. If this fails,giving you a SIP exception that means you most likely dont have permission to view certain project areas in RTC. You need to get the context ids of the project areas you do have access to and pass it to the queryItemsInContext method (this does the same thing as queryItems but looks only in the project area you specified through the context ids)
After that,you have to loop through each IQueryPage and in each of these extract the IItemHandles as follows -
List<IItemHandle> itemList = qpage.getItemHandles();
You have to then resolve these IItemHandles to the corresponding IItem .
This API allows you to query anything, from comments to modified by,approvals and any common or custom attribute.
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 04 '13, 5:22 a.m.I kept opening this question so I changed the topic to make sure people understand that this is not about regular queries.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 04 '13, 5:25 a.m.I have not tried to create queries that look for approvals. Have you tried to create such a query in the UI, save it and look at how it is composed? Another approach might be to plugin-spy the Eclipse query editor with the SDK installed to find how it handles his case.
Anurag Chaudhury
Mar 04 '13, 2:46 p.m.Hi. I am not sure how to decompose the query, as in see how it is implemented through the API. In the UI, I can select the Approvals and then say select, State and the state is Approved.