How do I access attribute values when I am receiving assertion errors through Plain Java API
3 answers
which prints out the attributes of workitems from a query result
Comments
Where are you getting the com.ibm.team.apt.common and com.ibm.team.apt.internal.client apis? They weren't in the Plain Java jar files I found on the jazz website
those are in the SDK.
you could remove them and comment out the code
Thanks for the help! I tried your code and it initially didn't find the attribute for the work item. Once I set a value for the attribute though it found it with no problem. I assumed if I could see the field in workItem online, I should be able to access it. But I can only access it if it was assigned a value.
hm.. the code should always print an attributes value even when null.
it does NOT print user names, or data/time values.
what kind of attribute is it?
In any case you should check if the work item has the attribute with hasAttribute(IAttribute). See https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
As a side note, you should not use the com.ibm.team.apt.common and com.ibm.team.apt.internal.client api unless you are working with plans (which is unsupported) use the com.ibm.team.workitem.client. and com.ibm.team.workitem.common API's that are also available in the plain Java Client Libraries.
Comments
Thanks for the help! I think what you said about synchronizing attributes may be the issue. The field itself has been added to the old workItems, but using Sam's code the attribute only shows up if I manually change the value of it. And once the value is changed my code works as well. Is this what you were saying? Should I still be able to see the attribute field on an old workItem even if it hasn't been synchronized?
no.. unless you synch, the attribute is NOT there on old workitems.
// loop thru all the workitem attributes
for (IAttribute ia : workItemCommon.findAttributes(projectArea,
monitor))
{
// if this workitem has this attribute and
// its nOT an internal use attribute
if (workItem.hasAttribute(ia) && !ia.isInternal())
Comments
Sam, you didn't report the assertion error.
I catch the assertion error and use it to determine other attribute features
.....
// this will throw exception if not enumeration
IEnumeration<iliteral> enumeration = (IEnumeration<iliteral>) workItemCommon
.resolveEnumeration(ia, monitor);
catch (Exception e)
{
System.out.println("\t\t\t\tattribute id="