It's all about the answers!

Ask a question

How to Create Expression for Planned for attribute using Java API

Navin R S (13512) | asked Sep 19 '17, 7:39 a.m.
edited Sep 19 '17, 7:47 a.m.

Hello All,


We are trying to create Query from Java API(we don't want to run the shared Query), the condition should include Project area, Modified Date and Planned For Attribute. we are trying the below code but we are getting below exception

Exception in thread "main" java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle             at             at$ConstantValue.saveState(             at             at             at             at             at             at             at  


The code we are trying is mentioned below for Planned for attribute

IQueryableAttribute workItemPlannedForAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE)

        .findAttribute(projectArea,, auditableClient, null);

    AttributeExpression workItemPlannedForExpression =

        new AttributeExpression(workItemPlannedForAttribute, AttributeOperation.MATCHES, PlannedFor);


Accepted answer

permanent link
Ralph Schoon (62.7k33643) | answered Sep 19 '17, 10:08 a.m.
edited Sep 19 '17, 10:09 a.m.

 You need to be careful with the operations. MATCHES is full text or text compare. Some example code:

        IAuditableCommon auditableCommon = (IAuditableCommon) teamRepository

    DevelopmentLineHelper devLineHelper = new DevelopmentLineHelper(teamRepository, monitor);
    IIteration targetIteration = devLineHelper.findIteration(projectArea, Arrays.asList(iteration.split("/")), DevelopmentLineHelper.BYLABEL);

    IQueryableAttribute attribute = QueryableAttributes.getFactory(
            IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor);
    Expression inProjectArea = new AttributeExpression(attribute,
            AttributeOperation.EQUALS, projectArea);
    IQueryableAttribute plannedFor = QueryableAttributes.getFactory(
            IWorkItem.TARGET_PROPERTY, auditableCommon, monitor);
    Expression isPlannedFor = new AttributeExpression(plannedFor,
            AttributeOperation.EQUALS, targetIteration);

    Term typeinProjectArea = new Term(Term.Operator.AND);

See for the development line helper code.

Navin R S selected this answer as the correct answer

Navin R S commented Nov 24 '17, 12:51 a.m.

Thanks for the Reply. Its Working Now

Your answer

Register or to post your answer.