It's all about the answers!

Ask a question

WorkItemClient findAttribute returns null for Acceptance field


Ambarish Mohan (611) | asked Feb 21 '15, 7:39 a.m.
Hello,

I am trying to fetch the "Acceptance Criteria" attribute of the story work item, using the plain java RTC api through the following code.

IAttribute attribute=workItemClient.findAttribute(workItem.getProjectArea(), "com.ibm.team.apt.attribute.acceptance", monitor);

The above code  works fine with jazz.net sandbox(version 5.0.2) and returns the IAttribute instance of the relevant work item.
 But it returns null when tested with RTC version 4.0.6 repository. Kindly let me know what could be the issue with 4.0.6 repository?

Note:  I have changed the java RTC api version accordingly.

Expecting your valuable reply.

thanks
Ambarish

2 answers



permanent link
sam detweiler (12.5k6195201) | answered Feb 21 '15, 8:18 a.m.
I don't know the answer, but it might help to list out all the attributes found for that workitem type.

note this field is ONLY for story type workitems.

I use this on my sample code here
if (workItem.hasAttribute(ia) && !ia.isInternal())



Comments
Ambarish Mohan commented Feb 21 '15, 8:57 a.m.

Thanks a lot.
This is very much helpful to track the list of attributes.
But my problem still remains! Can any one please help me in this regard


sam detweiler commented Feb 21 '15, 12:31 p.m.

and you don't have an accidental space char in the name, right?

if you dump out the attributes, is that attribute present? again, remember it will only be there for Story type workitems.

make a query that just lists one workitem, then use that with my sample pgm, which dumps attributes of workitems in queries


Ambarish Mohan commented Feb 23 '15, 11:55 a.m.

Yes.
I tried to dump out all the attributes for the Story Work Item.  In my jazz.net sandbox(5.0.2 ) i am able to see the identifier "com.ibm.team.apt.attribute.acceptance"  for the attribute "Acceptance Test".

The same attribute list for RTC version 4.0.6 contains the attribute "Acceptance Test", but its identifier value is "acceptance".

May this could be an issue , do you have any pointers to fix it?


Ambarish Mohan commented Feb 23 '15, 9:02 p.m.

Exactly you are correct. How to change the short name "acceptance" to the long name identifier value. Please assist me.


sam detweiler commented Feb 23 '15, 9:56 p.m.

you cannot change the ID. you 'could' create another attribute with a different name and the right ID, then export all the current story work items id and acceptance test field,

rename the old field out of the way, rename the new field with the old name (but the right ID), and then import/update all the workitems to put the old data in the new field.
but you cannot delete the old attribute... so the ugliness shows thru.

I would change your code a tiny bit, and if the get fails with null for the long ID string, try the short ID string instead.  Make this a routine and return the value of the field. and inside handle the retry.


Ambarish Mohan commented Feb 23 '15, 10:02 p.m.

Thanks for your reply.
But this is a system where i have read only access. I can't create an attribute or modify anything.
i tried with both the long and short IDs to fetch the acceptance value. Both of them fails with null. Is it possible to successfully retrieve the attribute value using the short ID?


sam detweiler commented Feb 23 '15, 10:08 p.m.

Yes, it should work using the short ID.. note you have to use ID not the NAME.


Ambarish Mohan commented Feb 23 '15, 10:13 p.m.

But sam,
both
IAttribute attribute=workItemClient.findAttribute(workItem.getProjectArea(), "com.ibm.team.apt.attribute.acceptance", monitor);

and

IAttribute attribute=workItemClient.findAttribute(workItem.getProjectArea(), "acceptance", monitor);

returns null


sam detweiler commented Feb 23 '15, 10:30 p.m.

can you run my utility, and see what is actually used for that attribute?

create a query that dumps 1 story workitem.  then use the utility to dsplay the attributes of the workitem.

it should have worked with the short id string


Ambarish Mohan commented Feb 23 '15, 10:57 p.m.

In order to run the utility i don't have these classes resolved in my classpath
import com.ibm.team.apt.common.IIterationPlanRecord;
import com.ibm.team.apt.common.IIterationPlanRecordHandle;
import com.ibm.team.apt.internal.client.IIterationPlanClient;
import com.ibm.team.apt.internal.client.IterationPlanClient;

What are all the jars i need to download.? The Plain java API for 4.06 lacks these classes.
Please advice.


sam detweiler commented Feb 24 '15, 7:08 a.m.

sorry, those are in the sdk plugins folder. you can comment out the imports. they are not used


Ambarish Mohan commented Feb 24 '15, 9:27 a.m.

Usage: QueryWorkItems <repositoryuri> <userid> <password> <projectarea> <queryname>

What will be the valid command line argument for <queryname> ??


sam detweiler commented Feb 24 '15, 9:53 a.m.

that is the name string of the workitem query you created via eclipse or the web ui.
my code doesn't create a query on the fly, it uses an existing query created manually.

note that you may need to add the attributes to the query output. the default only has a few


Ambarish Mohan commented Feb 24 '15, 10:14 a.m.

Can you please give me an example query?


sam detweiler commented Feb 24 '15, 10:21 a.m.

sure, create a query named 'all storys', which selects workitem type=story,
save it, run it manually

then use "all storys" as the parameter for the query name


sam detweiler commented Feb 24 '15, 12:26 p.m.

Hm.. Ralph.. I run my utility, executing a query as above, has 1 story workitem..
(4.0.6 GM)

I get class not found  (using the plainjava classes)
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/team/workitem/api/common/ExtendedRichTextSupport
    at com.ibm.team.workitem.common.model.AttributeTypes.<clinit>(AttributeTypes.java:148)

it is not in the com.ibm.team.workitem.api.common jar.
I looked in all the workitem jar files, not there
I can't find this class.


1
sam detweiler commented Feb 24 '15, 3:30 p.m.

never mind, somehow this project also is considered a plugin project, so the plugin platform jars were included incorrectly..

works and dumps out , for my 4.0.6 test project.

            processing for variable=Acceptance Test attrib type=html kind=_meta custom attribute
                attribute id=com.ibm.team.apt.attribute.acceptance, type=html value=some data


Ambarish Mohan commented Feb 25 '15, 8:07 p.m.

This is my output

 processing for variable=Acceptance Test attrib type=html kind=_meta custom attribute
                attribute id=acceptance, type=html value=Test

Kindly help me to solve this issue.


Ambarish Mohan commented Feb 25 '15, 10:04 p.m.

Also sam,
what is the difference between using
workItemClient and workItemCommon ?

IAttribute attribute:workItemClient.findAttributes(---)
and
IAttribute ia:workItemCommon.findAttributes(---)


Ralph Schoon commented Feb 26 '15, 1:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

So the ID you should use with this process area is "acceptance".

WorkItem Client shares the method from Work Item Common.


Ambarish Mohan commented Feb 26 '15, 3:16 a.m.

Oh Ok fine Ralph.
Thanks a ton guys.
At last,
workItemCommon.findAttributes(--) returns the attribute with id "acceptance" whereas workitemClient.findAttributes(--) returns nothing related to "acceptance."

why this kind of difference?

showing 5 of 21 show 16 more comments

permanent link
sam detweiler (12.5k6195201) | answered Feb 23 '15, 12:17 p.m.
I see the long name for my 4.0.6 installation
if you only see the shortname, that is clearly why the request for the longname will return null. (cause the longname is not found)



Comments
Ralph Schoon commented Feb 24 '15, 3:33 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I think the valid answer is that you have to provide a valid, existing attribute ID, otherwise findAttribute returns null - as described in the code.


Ambarish Mohan commented Feb 24 '15, 6:56 a.m.

But, the valid existing attribute ID is "acceptance". But findAttribute still returns null. This is where my exact problem is.


Ralph Schoon commented Feb 24 '15, 7:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Did you check if the item actually has the attribute? If the attribute has been introduced later, it might not be available. Sam provided you with the code above. You would have to synchronize attributes to make sure.


Ralph Schoon commented Feb 24 '15, 7:07 a.m. | edited Feb 24 '15, 7:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Sorry, forget the last statement. You can use https://rsjazz.wordpress.com/2015/02/09/a-rtc-workitem-command-line-version-2/ to check for the attribute ID's it will however only report back the internal ID's for built in attributes.


Ambarish Mohan commented Feb 24 '15, 8:15 a.m.

Yes Ralph. The tool returns a set of attributes among which "Acceptance Test" is not listed as it doesn't belongs to the built-in attributes.

But i don't know how to retrieve the non-built-in attributes.


Ralph Schoon commented Feb 24 '15, 8:23 a.m. | edited Feb 24 '15, 8:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

https://rsjazz.wordpress.com/2015/02/09/a-rtc-workitem-command-line-version-2/ returns the built in as well as the custom attributes. If the attribute does not show for a type, it is not available on the type - which explains the null value.


sam detweiler commented Feb 24 '15, 8:29 a.m.

But this is Story Acceptance Test which has been there since the late 3.x days.
and he is getting failure on 4.0.6.


Ralph Schoon commented Feb 24 '15, 8:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

It might have an internal/short name. I don't have 4.0.6 available right now.
I don't know what is going on, but is the attribute is not listed and can not be found, then there is something going on.

If I wanted to, I could also create a template where the attribute is not available.

Not sure what is going on, my experience so far has been however, that the API  is very stable and if it does not find an attribute of a specific ID, it is simply not there.

Most of the errors I have seen were caused by me, doing something wrong and not a faulty API.

The same API is used for queries, does the attribute show up? With a N/A?

He could review the process XML and look if there is something suspicious. He can use hasAttribute(), etc. I think story has several attributes that are marked as custom.


Ambarish Mohan commented Feb 24 '15, 8:40 a.m.

The attribute is not showing in the result whereas through the code,
for(IAttribute ia:workItemClient.findAttributes(storyWorkItem.getProjectArea(), monitor)){
                if(storyWorkItem.hasAttribute(ia)&&(!ia.isInternal()))
                    LoggerUtility.log(ia.getDisplayName()+"::"+ia.isBuiltIn()+"::"+ia.getIdentifier(),Level.INFO);
            }

It prints the attribute.
But my problem is, the ID for the attribute value returned in RTC 4.0.6 is "acceptance" whereas in RTC 5.0.2 the ID value is "com.ibm.team.apt.attribute.acceptance"


Ralph Schoon commented Feb 24 '15, 9:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

i meant running a query in the tool and select the attributes you want to see.


Ambarish Mohan commented Feb 24 '15, 9:44 a.m. | edited Feb 24 '15, 9:45 a.m.

That attribute "Acceptance Test" is not at all being listed in the tool output. Even for version 5.0.2 it is not getting listed in the tool output.


Ralph Schoon commented Feb 26 '15, 1:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Then you don't have the attribute in your template. It was either removed or you use a template without it. Look at the editor presentations and try to identify which attribute is used, if at all.

showing 5 of 12 show 7 more comments

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.