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

How to Create Expression for Planned for attribute using Java API

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 com.ibm.team.workitem.common.internal.model.SetAttributeType.toString(SetAttributeType.java:73)             at com.ibm.team.workitem.common.internal.expression.AttributeValueFactory$ConstantValue.saveState(AttributeValueFactory.java:58)             at com.ibm.team.workitem.common.expression.AttributeExpression.saveValueProxy(AttributeExpression.java:175)             at com.ibm.team.workitem.common.expression.AttributeExpression.saveState(AttributeExpression.java:165)             at com.ibm.team.workitem.common.expression.Term.saveState(Term.java:209)             at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:137)             at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:56)             at com.ibm.team.workitem.common.internal.query.impl.QueryDescriptorCustomImpl.setExpression(QueryDescriptorCustomImpl.java:93)             at com.ibm.team.workitem.common.internal.query.impl.QueryDescriptorCustomImpl.setExpression(QueryDescriptorCustomImpl.java:86)  

 

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

IQueryableAttribute workItemPlannedForAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE)

        .findAttribute(projectArea, com.ibm.team.workitem.api.common.IWorkItem.PLANNED_FOR, auditableClient, null);

    AttributeExpression workItemPlannedForExpression =

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






				

0 votes


Accepted answer

Permanent link

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

        IAuditableCommon auditableCommon = (IAuditableCommon) teamRepository
                .getClientLibrary(IAuditableCommon.class);

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

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

    Term typeinProjectArea = new Term(Term.Operator.AND);
    typeinProjectArea.add(inProjectArea);
    typeinProjectArea.add(isPlannedFor);

See https://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/ for the development line helper code.

Navin R S selected this answer as the correct answer

0 votes

Comments

Thanks for the Reply. Its Working Now

Your answer

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
× 1,701
× 1,220

Question asked: Sep 19 '17, 7:39 a.m.

Question was seen: 2,759 times

Last updated: Nov 24 '17, 12:51 a.m.

Confirmation Cancel Confirm