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

RTC Server API code to find the result of a query

 I have to develop a plugin on RTC which will run when a query on a project area and store the result in a customized attributes. 


for example -  query as - 

Major Defect = Number of Defects wich respect those conditions for the currunt milestone : <o:p> </o:p>

·         Subtype :  external AND <o:p> </o:p>

·         Severity : Major AND <o:p> </o:p>

·         Status IS NOT Info Requested or Reject AND <o:p> </o:p>

Query Name : Open Defect – Result : 42 defects. Get the “42” and put it on a custom attribute .

How to do it .

0 votes



3 answers

Permanent link

You could try to start with: https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/

Note that the api is client API. You will have to try to find common API in the server. E.g.

instead of

IWorkItemClient
use
IWorkItemCommon

I haven'd tried thisin the server API, so that is all I have.

0 votes


Permanent link

Vivek,
I have done similiar things several times.
This is a code snippet to build and execute a query on work items:

IQueryableAttributeFactory queryAttrFactory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
IQueryableAttribute projectAreaAttribute = queryAttrFactory.findAttribute(projectAreaHandle,IWorkItem.PROJECT_AREA_PROPERTY, utility.workItemCommon.getAuditableCommon(), utility.monitor);
AttributeExpression projectAreaExpression = new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectAreaHandle);
IQueryableAttribute typeAttribute = queryAttrFactory.findAttribute(projectAreaHandle,IWorkItem.TYPE_PROPERTY, utility.workItemCommon.getAuditableCommon(), utility.monitor);
AttributeExpression typeExpression = new AttributeExpression(typeAttribute, AttributeOperation.EQUALS, "allowedreference");
IQueryableAttribute referencingWIAttribute = queryAttrFactory.findAttribute(projectAreaHandle, referencingWorkItemTypeAttribute, utility.workItemCommon.getAuditableCommon(), utility.monitor);
AttributeExpression referencingWIExpression = new AttributeExpression(referencingWIAttribute, AttributeOperation.EQUALS, referencingWI);
        
IQueryCommon queryService = getService(IQueryCommon.class);
                
Term term = new Term(Term.Operator.AND);
term.add(projectAreaExpression);
term.add(typeExpression);
term.add(referencingWIExpression);
        
IQueryResult<IResolvedResult<IWorkItem>> queryResult = queryService.getResolvedExpressionResults(projectAreaHandle, term, IWorkItem.FULL_PROFILE);

Then you loop over the result set:

int resultSize = queryResult.getResultSize(utility.monitor).getTotal();
        
if (resultSize>0) {    
    while (queryResult.hasNext(utility.monitor)) {
    IResolvedResult<IWorkItem> resolvedResultWI = queryResult.next(utility.monitor);
    IWorkItem resolvedWI = resolvedResultWI.getItem();
    // .....
    }
}
I hope it helps.

0 votes

Comments

 Hi Luca, even if your code really makes sense, I would keep the main loop about queryResult.hasNext and for every page I would check queryResult.getResultSize to see if there are results on that page.


Permanent link

 Hi, thanks and sorry for a question, I try to execute your code, as well as that of Ralph that I have seen on other posts, but unfortunately I always get this error:


Exception checking precondition. An unhandled exception occurred during "Prohibit Save (ASISE)".
Argument must be an instance of IAuditableHandle.
Now do not notice you have details but it is a CustomAdvisor that gives the problem as if I had not instantiated something correctly but what ?? Thanks.

0 votes

Comments

The classes used in the API, that represent objects, can be either basic stuff such as String, or it can be more complex stuff. Usually these are represented by a handle e.g. IWorkitemHandle. Things that get traced in history are usually implementing IAuditableHandle. So somewhere in your code you pass a wrong class/interface. 

 Good morning, and I imagined it was something similar, in fact I used the plannedFor as a parameter convinced that it was right, but using a string that replicates the value of the PlannedFor I managed to run the query. Thanks.

Good it is working for you now. 

Please ask your own question next time to not pollute existing content. Also please understand the difference between a comment and an answer. 

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

Question asked: Sep 14 '17, 5:53 a.m.

Question was seen: 4,492 times

Last updated: May 11 '20, 3:51 a.m.

Confirmation Cancel Confirm