It's all about the answers!

Ask a question

Issue while accessing workitems from repository using server side api

Pallavi Deore (3817) | asked Jun 17 '19, 12:37 a.m.

Hello Everyone,

I am using CLM 6.0.6.
I want to develop an Advisor plugin which should allow only a single occurrence of value in attribute tcr_id which is of type Large String.
I have created below code using server side java api to fetch all workitems from repository which contains some specific value in custom attribute tcr_id.
tcr_id contains value like: "124-"

Code is below:

IQueryableAttribute projectareaAttribute= QueryableAttributes
IWorkItem.PROJECT_AREA_PROPERTY, fAuditableCommon,
//get workitem type attribute
IQueryableAttribute typeAttribute = QueryableAttributes.getFactory(
IWorkItem.TYPE_PROPERTY, fAuditableCommon, monitor);
IQueryableAttribute proxyIDAttribute = QueryableAttributes.getFactory(
IWorkItem.ITEM_TYPE).findAttribute(projectArea,"", fAuditableCommon,
Expression inProjectAreaExpression = new AttributeExpression(
projectareaAttribute, AttributeOperation.EQUALS, projectArea);
Expression isTypeExpression = new AttributeExpression(typeAttribute,
Expression proxyIDExpression = new AttributeExpression(
proxyIDAttribute, AttributeOperation.CONTAINS, CAIDobject); //Get the value of large string attribute into CAIDobject which of type Object
Term term = new Term(Operator.AND);
IQueryResult results = fQueryCommon.getExpressionResults(
projectArea, term);
List <WorkItem>Sameworkitems = new ArrayList<WorkItem>();
int resultSize =  results.getResultSize(monitor).getTotal(); //queryResult.getResultSize(utility.monitor).getTotal();
    IResult result = (IResult);
IWorkItemHandle resultHandle = (IWorkItemHandle) result.getItem();
IWorkItem BPM = (IWorkItem) wis
.resolveAuditable(resultHandle, IWorkItem.FULL_PROFILE,
Its working till line of code: System.out.println(resultSize);
But I got exception in line of above code "while(results.hasNext(monitor)".
Kindly checked the above code, Is it correct to fetch workitems based on custom attribute value???
Kindly provide me assistance.


Pallavi Deore commented Jun 18 '19, 8:01 a.m.

How to fetch work items from RTC containing same value in attribute as workingcopy is having using server side API.

I used above code but getting 0 result.

Kindly help??? 

Luca Martinucci commented Jun 18 '19, 8:43 a.m.

What do you get as resultSize?

Usually, you get an exception when you use the hasNext method on an empty result.
if (resultSize>0) {
while (results.hasNext(monitor)) {
Anyway, the filters on the project area and on the type look fine, I would focus on the

Pallavi Deore commented Jun 18 '19, 8:57 a.m.

 Hi Luca,

I tried with if (resultSize>0) {
while (results.hasNext(monitor)) {

I have doubt on above code to access work items using query API. Is the proxyIDExpression is correct or not??? 

Be the first one to answer this question!

Register or to post your answer.