It's all about the answers!

Ask a question

How to display value of custom attribute by running query programmatically(Java Client API)

vikrant kamble (1323396) | asked Sep 23 '15, 5:13 a.m.
 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);
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

permanent link
Miguel Tomico (5001423) | answered Sep 23 '15, 5:52 a.m.
This question has been answered many times here in the forum.
Ralph's blog post explains how to retrieve the value of a custom attribute:

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);

permanent link
Ralph Schoon (63.2k33646) | answered Sep 23 '15, 5:53 a.m.
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, and

Your answer

Register or 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.