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

Issue while accessing workitems from repository using server side api

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



0 votes

Comments

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??? 

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.

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

Question asked: Jun 17 '19, 12:37 a.m.

Question was seen: 1,480 times

Last updated: Jun 18 '19, 8:57 a.m.

Confirmation Cancel Confirm