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

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

1

0 votes

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.


This,returns all the Approved WIs.

Also, I tried handling this case like handling other attributes(creating an IQueryable Attribute, inserting that into the AttributeExpression and the term and then running this )

IQueryResult<IResolvedResult<IWorkItem>> result = rtcInternalAttribute.get_queryService().getResolvedExpressionResults
(rtcInternalAttribute.get_projectArea(), term,  IWorkItem.FULL_PROFILE);


However, that gives me an exception saying an instance of IAuditableHandle was expected. 



One answer

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

0 votes

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,938

Question asked: Mar 01 '13, 5:26 p.m.

Question was seen: 4,753 times

Last updated: Mar 11 '13, 12:23 p.m.

Confirmation Cancel Confirm