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.
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 .
3 answers
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
IWorkItemClientuse
IWorkItemCommon
I haven'd tried thisin the server API, so that is all I have.
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.
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: