Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Question about how to get custom attributes

 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?

0 votes


Accepted answer

Permanent link
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 votes


2 other answers

Permanent link
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>

0 votes

Comments

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

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

"attributeName"

so I was confused.

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.

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?

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

0 votes

Comments

 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")){

Solved, thanks a lot...

Can u tell us what u ended up doing? 

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

 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 log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,927
× 368

Question asked: May 30 '14, 3:38 p.m.

Question was seen: 5,934 times

Last updated: Jun 06 '14, 9:20 p.m.

Confirmation Cancel Confirm