How to query a work item based on a custom attribute?
How to query a work item based on a custom attribute? I'm trying the following code, but always getting null for queryableCustom in the code below.
IAuditableClient auditableClient = (IAuditableClient) teamRepository
.getClientLibrary(IAuditableClient.class);
IQueryableAttribute queryableCustom = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE)
.findAttribute(processArea, "cmvc_name", auditableClient, monitor);
System.out.println("queryableCustom="+queryableCustom);
Expression attributeExpression = new AttributeExpression(queryableCustom,
AttributeOperation.EQUALS, defectName);
System.out.println("attributeExpression="+attributeExpression);
IQueryClient queryClient = (IQueryClient) teamRepository
.getClientLibrary(IQueryClient.class);
IQueryResult<IResolvedResult<IWorkItem>> result = queryClient.getResolvedExpressionResults(
processArea, attributeExpression, IWorkItem.FULL_PROFILE);
if (result.hasNext(monitor)) {
IResolvedResult<IWorkItem> resolved = result.next(monitor);
System.out.println("Name="+resolved.getItem().getHTMLSummary());
return resolved.getItem();
}
2 answers
How to query a work item based on a custom attribute? I'm trying the following code, but always getting null for queryableCustom in the code below.
IAuditableClient auditableClient = (IAuditableClient) teamRepository
.getClientLibrary(IAuditableClient.class);
IQueryableAttribute queryableCustom = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE)
.findAttribute(processArea, "cmvc_name", auditableClient, monitor);
System.out.println("queryableCustom="+queryableCustom);
Expression attributeExpression = new AttributeExpression(queryableCustom,
AttributeOperation.EQUALS, defectName);
System.out.println("attributeExpression="+attributeExpression);
IQueryClient queryClient = (IQueryClient) teamRepository
.getClientLibrary(IQueryClient.class);
IQueryResult<IResolvedResult<IWorkItem>> result = queryClient.getResolvedExpressionResults(
processArea, attributeExpression, IWorkItem.FULL_PROFILE);
if (result.hasNext(monitor)) {
IResolvedResult<IWorkItem> resolved = result.next(monitor);
System.out.println("Name="+resolved.getItem().getHTMLSummary());
return resolved.getItem();
}
I was able to resolve this problem. The above code works fine, the problem was that I was using wrong project area which did not have that custom attribute.