It's all about the answers!

Ask a question

Question about how to get custom attributes


Vinícius Rabelo (825) | asked May 30 '14, 3:38 p.m.
edited May 30 '14, 3:40 p.m.
 Hi,

I am begginer with RTC Java API’s and I am having problems to load custom attributes values... I believe that my question is relative about concepts, but I already read some articles but the questions continue...
I found a lot of informations here: http://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ but didn't solve my questions...
I want to get custom attributes from IWorkItem, then i have:

<code>
....
//Search work items from project area here
List<IWorkItem> workItems = searchByProjectArea("Project Area X");
for (IWorkItem iWorkItem : workItems) {
IAttribute att = workItemClient.findAttribute(iWorkItem.getProjectArea(),
"attributeName", null);
// Shouldn't be workItemClient.findAttribute(iWorkItem, "attributeName", null)?????? My custom attribute is at workitem and not at project area
if (iWorkItem.hasAttribute(att )) {
System.out.println("OK!!!!!");
} else {
System.out.println("Error!!! Always stop here");
}
}
</code>

What it's wrong?

Accepted answer


permanent link
sam detweiler (12.4k6173200) | answered May 30 '14, 3:58 p.m.
edited May 30 '14, 6:19 p.m.
its not attribute name, it attribute ID..

I always give my workitem attributes IDs I can figure out

com.xx.workitem.attribute.name

here is a link to my utility which prints out values of workitem attributes (workitems returned from query but not any different once u have the workitem)
see the accepted answer here
https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes

watch out, the forum changes text case for anything near a < or > character, so when u cut/paste this into an eclipse project java file, you will get some errors

Ralph Schoon selected this answer as the correct answer

2 other answers



permanent link
Vinícius Rabelo (825) | answered May 30 '14, 4:58 p.m.
edited May 30 '14, 5:00 p.m.
Hi Sam, thanks your answer...
I am getting by attribute ID, not by attribute name...
 
Does your script don't get custom attributes, correct? The attributes that I want are custom...
What do you say about this:
<code>
workItemClient.findAttribute(iWorkItem.getProjectArea(),
"attributeName", null);
// Shouldn't be workItemClient.findAttribute(iWorkItem, "attributeName", null)?????? My custom attribute is at workitem and not at project area
</code>

Comments
sam detweiler commented May 30 '14, 5:18 p.m.

my sample does ALL attributes, custom or not.. you can make it JUST custom
with a tiny little change  near the top of routine

  static void printAttributes(IWorkItem workItem,
            IAuditableClient auditableClient, IProjectArea projectArea,
            org.eclipse.core.runtime.IProgressMonitor monitor, ITeamRepository repository, String XML)

change this

            for (IAttribute ia : workItemCommon.findAttributes(projectArea,
                    monitor))

to this
            for (IAttribute ia : workItem.getCustomAttributes())


sam detweiler commented May 30 '14, 6:20 p.m.

and u SAY you are not using the NAME, but then the pseudo code you show says

"attributeName"

so I was confused.


sam detweiler commented May 30 '14, 6:26 p.m.

and for the specific question you asked

this is the access method provided..

for ALL attributes, you can get the IAttribute objects in a list from the Project Area.

then you have to check to see if THIS workitem HAS each attribute.
        if (workItem.hasAttribute(ia)  && !ia.isInternal())

for JUST custom attributes, you can get the IAttribute objects in a list from the Workitem.
then that test will always be true.

just the way the API works.


Vinícius Rabelo commented Jun 02 '14, 4:05 p.m.
Thanks your answer, i take a little time to answer because the weekend...

I said  "attributeName" because I made a mistake but I used attribute id...

If i travel all workitems from my project and I verify workItem.hasAttribute(ia), this never is true...
But if I look at RTC client (eclipse) at Project Area --> Tab Process Configuration --> Configuration Tree -> Project Configuration --> Configuration Data --> Work itens --> Types and attributes my attribute it's here...

Do you know what can be wrong?

sam detweiler commented Jun 02 '14, 4:10 p.m.

Any workitems created BEFORE you added the configuration info will not jg ave those new attributes until you do a synchronize operation on them. 


U can do the synch in eclipse in the process editor.  


permanent link
Vinícius Rabelo (825) | answered Jun 03 '14, 3:11 p.m.
I did the synchronization, but isn't working...
Does all workitem have the attribute ID? Then if i try to get the workitem ID, at any workitem, like this:
<code>
for (IAttribute ia : workItemCommon.findAttributes(projectArea, monitor)) {
if(ia.getIdentifier().equals("com.ibm.team.workitem.attribute.id")){
if ((workItem.hasAttribute(ia) || workItem
.hasCustomAttribute(ia)) && !ia.isInternal()) {
System.out.println("OK");
}
}
}
</code>
This should be true at some moment, Am I correct? But this is not working...

Comments
sam detweiler commented Jun 03 '14, 3:22 p.m.

 if(ia.getIdentifier().equals("com.ibm.team.workitem.attribute.id")){



watch out for mixed case literals.. I think it is 'workItem'..

so 

if(ia.getIdentifier().equalsIgnoreCase("com.ibm.team.workitem.attribute.id")){


Vinícius Rabelo commented Jun 05 '14, 6:01 p.m.

Solved, thanks a lot...


sam detweiler commented Jun 05 '14, 6:04 p.m.

Can u tell us what u ended up doing? 


Vinícius Rabelo commented Jun 06 '14, 5:56 p.m.
Sure... I am beginner, then I was making confusion... I identify two problems:
- I was using small profile and didn't come the necessary attributes
- Were necessary to make synchronize operation...

Thanks a lot

sam detweiler commented Jun 06 '14, 9:20 p.m.

 Thank you. Others who are beginners can learn from your experience.


I try to use full profile all the time unless I have a specific reason to be selective.

Your answer


Register or to post your answer.