How to query work items using Approvals with the API?
Anurag Chaudhury (71●1●2)
| asked Mar 01 '13, 5:26 p.m.
edited Mar 04 '13, 5:21 a.m. by Ralph Schoon (63.4k●3●36●46)
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.
|
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.
Comments
I kept opening this question so I changed the topic to make sure people understand that this is not about regular queries.
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.
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.