It's all about the answers!

Ask a question

Issue while accessing workitems from repository using server side api


Pallavi Deore (38150) | 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
.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea,
IWorkItem.PROJECT_AREA_PROPERTY, fAuditableCommon,
monitor);
//get workitem type attribute
IQueryableAttribute typeAttribute = QueryableAttributes.getFactory(
IWorkItem.ITEM_TYPE).findAttribute(projectArea,
IWorkItem.TYPE_PROPERTY, fAuditableCommon, monitor);
IQueryableAttribute proxyIDAttribute = QueryableAttributes.getFactory(
IWorkItem.ITEM_TYPE).findAttribute(projectArea,"tcr.id", fAuditableCommon,
monitor);
Expression inProjectAreaExpression = new AttributeExpression(
projectareaAttribute, AttributeOperation.EQUALS, projectArea);
Expression isTypeExpression = new AttributeExpression(typeAttribute,
AttributeOperation.EQUALS,
"task");
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);
term.add(inProjectAreaExpression);
term.add(isTypeExpression);
term.add(proxyIDExpression);
IQueryResult results = fQueryCommon.getExpressionResults(
projectArea, term);
List <WorkItem>Sameworkitems = new ArrayList<WorkItem>();
int resultSize =  results.getResultSize(monitor).getTotal(); //queryResult.getResultSize(utility.monitor).getTotal();
     System.out.println(resultSize);
while(results.hasNext(monitor)) 
{
    IResult result = (IResult) results.next(monitor);
IWorkItemHandle resultHandle = (IWorkItemHandle) result.getItem();
IWorkItem BPM = (IWorkItem) wis
.getAuditableCommon()
.resolveAuditable(resultHandle, IWorkItem.FULL_PROFILE,
monitor).getWorkingCopy();
                }
/////////////////////////
 
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.

Regards
Pallavi




Comments
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.
Try:
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
proxyIDExpression.


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.


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.