How to get the WorkItems based on "Filed Against" value?
We want to fetch the WorkItems based on specific "Field Against" value set. The below code didn't work for me and gives the error. Can you please let us know what could be wrong? Thanks in advance
I didnt find IWorkItem.FILED_AGAINST_PROPERTY hence i used CATEGORY_PROPERTY and TestProj/UI1 is the filed against value that set.
-----------
IQueryableAttribute filedAgainstAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.CATEGORY_PROPERTY, auditableClient, monitor);
AttributeExpression filedAgainstExpression = new AttributeExpression(filedAgainstAttribute, AttributeOperation.EQUALS, XMLString.createFromPlainText("TestProj/UI1"));
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(projectArea, filedAgainstExpression, IWorkItem.FULL_PROFILE);
------------------------------------
It gives below error at last line in the above code snippet.
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)
I didnt find IWorkItem.FILED_AGAINST_PROPERTY hence i used CATEGORY_PROPERTY and TestProj/UI1 is the filed against value that set.
-----------
IQueryableAttribute filedAgainstAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.CATEGORY_PROPERTY, auditableClient, monitor);
AttributeExpression filedAgainstExpression = new AttributeExpression(filedAgainstAttribute, AttributeOperation.EQUALS, XMLString.createFromPlainText("TestProj/UI1"));
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(projectArea, filedAgainstExpression, IWorkItem.FULL_PROFILE);
------------------------------------
It gives below error at last line in the above code snippet.
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)
Accepted answer
You can't just put a string in there, I think. You have to find the category object from the string and then put in the ICategory object.
Comments
Thanks Ralph. I am able to figure it out with category list. The below code snippet would be helpful for others who are on same page.
private static String CATEGORY_NAME = "UI1";
List<ICategory> findCategories = workItemCommon.findCategories(projectArea, ICategory.FULL_PROFILE, monitor);
for(ICategory category : findCategories) {
if(category.getName().contains(CATEGORY_NAME)){
filedAgainstAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.CATEGORY_PROPERTY, auditableClient, monitor);
filedAgainstExpression = new AttributeExpression(filedAgainstAttribute, AttributeOperation.EQUALS, category);
}
}