It's all about the answers!

Ask a question

Querying Work Items by their planned for / target (RTC Java API)


Liam White (111) | asked Mar 06 '14, 10:26 a.m.
edited Mar 06 '14, 11:34 a.m. by Ralph Schoon (54.9k23642)
 Hi, 

I am trying to query work items that have a specific planned for / target but keep getting errors. I have tried the expression with both the name of the IIteration and the object itself (it's current state). Any help is much appreciated!

Here is my error currently:
com.ibm.team.repository.common.transport.ServiceMethodInvocationError: com.ibm.team.repository.common.query.QueryException: Unknown queryable field: target

and my code:
     IWorkItemClient workItemClient = (IWorkItemClient) getTeamRepository().getClientLibrary(IWorkItemClient.class);
   

    //Create a query factory
        IQueryableAttributeFactory factory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
        
        IQueryableAttribute typeAttribute = factory.findAttribute(getProjectArea(), IWorkItem.TARGET_PROPERTY, getAuditableClient(), getMonitor());
        
        //Begin writing our query expression
        AttributeExpression typeExpression = new AttributeExpression(typeAttribute, AttributeOperation.CONTAINS, versions.get(14));
         
        
        Term term= new Term(Operator.AND);
        term.add(typeExpression);

        //Execute query
        IQueryClient queryClient = (IQueryClient) getTeamRepository().getClientLibrary(IQueryClient.class);
        IQueryResult<IResolvedResult<IWorkItem>> result = queryClient.getResolvedExpressionResults(getProjectArea(), term, IWorkItem.FULL_PROFILE);
   

Comments
sam detweiler commented Mar 06 '14, 11:21 a.m.

did u try the iteration id (the string behind the label) 


Liam White commented Mar 06 '14, 11:27 a.m.

like so?


 AttributeExpression typeExpression = new AttributeExpression(typeAttribute, AttributeOperation.CONTAINS, versions.get(14).getLabel());

I have and I get this error:

java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle 


ramesh m commented Sep 29 '15, 10:26 a.m. | edited Aug 22 '17, 5:50 p.m.

 HI White,

           I am also trying to fetch the work items based on the current sprint,
I am also getting java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle .
below is my code,
IWorkItemClient workItemClient = (IWorkItemClient) iTeamRepository.getClientLibrary(IWorkItemClient.class);
IAuditableCommon iAuditableCommon = (IAuditableCommon) iTeamRepository.getClientLibrary(IAuditableCommon.class);

IQueryableAttribute planAttribute = factory.findAttribute(projectArea, IWorkItem.TARGET_PROPERTY, iAuditableCommon, monitor);
Expression plan = new AttributeExpression(planAttribute, AttributeOperation.EQUALS, CurrentMilestoneVariable.VARIABLE_ID);
Term term = new Term(Term.Operator.AND);
term.add(plan);
IQueryDescriptor iQueryDescriptor = queryClient.createQuery(projectArea, QueryTypes.WORK_ITEM_QUERY, "AllItems", term); --- getting exception at this line.
Please provide the solution if you did that.

regards, ramesh



Navin R S commented Aug 22 '17, 8:14 a.m. | edited Aug 22 '17, 5:50 p.m.

Hi Ramesh M,

I am also doing the same, trying to query work items that have a specific planned for.
Can you please share your solution if you have it already.


Thank you.

Regards,
Navin

Be the first one to answer this question!


Register or to post your answer.