How to display value of custom attribute by running query programmatically(Java Client API)
Hi All,
I want to display value of custom attribute by running query programatically using java client API
IQueryableAttribute attributecust=findAttribute(projectArea, auditableClient, attributeId, null);
AttributeExpression attributecustexpre=new AttributeExpression(attributecust,AttributeOperation.EXISTS,projectArea);
IQueryableAttribute projectAreaAttribute2=findAttribute(projectArea, auditableClient, IWorkItem.PROJECT_AREA_PROPERTY, null);
AttributeExpression projectAreaExpression2=new AttributeExpression(projectAreaAttribute2,AttributeOperation.EQUALS, projectArea);
Term term= new Term(Operator.AND);
term.add(projectAreaExpression2);
term.add(attributecustexpre);
ItemProfile<IWorkItem> profile= getProfile(projectAreaAttribute2);
return queryClient.getResolvedExpressionResults(projectArea, term, profile);
This code snippet returns work items that contain specified attributeId but in the output it displays work item id and summary of work item. Along with this I also want to display value of custom attribute. How do I do this.
Could anyone please help me here
Thank You
2 answers
This question has been answered many times here in the jazz.net forum.
Ralph's blog post explains how to retrieve the value of a custom attribute:
https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
Basically, retrieve the custom attribute:
IAttribute someAttribute= workItemClient.findAttribute(fProjectArea, "some_attribute_ID", monitor);
Then get the Work Item attribute value:
Object value = workItem.getValue(someAttribute);
Your code returns the work items that the query found and not just the Attribute. You have to get the attribute from the work item and then cast it to its type (or type handle) and return the value.
See: Understanding and Using the RTC Java Client API, https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/ and https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
See: Understanding and Using the RTC Java Client API, https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/ and https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/