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 . |
3 answers
Ralph Schoon (63.5k●3●36●46)
| answered Sep 14 '17, 7:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER You could try to start with: https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/
instead of IWorkItemClientuse IWorkItemCommon I haven'd tried thisin the server API, so that is all I have. |
Vivek,
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. Comments
Stefano Antoniazzi
commented Sep 28 '17, 10:37 a.m.
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. |
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.