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

Getting custom attributes names via Java API

I am trying to retrieve the list of custom attributes via Java API.
I've been able to retrieve a list of IAttributeHandle; can I get IAttribute from IAttributeHandle (in order to retrieve the name)?

0 votes


Accepted answer

Permanent link
 Based on Luca's comment, on the server side you can use the IRepositoryItemService class to achieve this.

IAttributeHandle handle = ...
IRepositoryItemService itemService = getService(IRepositoryItemService.class);
IAttribute attribute = (IAttribute) itemService.fetchItem(handle, IRepositoryItemService.COMPLETE);
Note that if you want to fetch a number of attribute handles you can use the IRepositoryItemService#fetchItems() method instead.
Luca Martinucci selected this answer as the correct answer

1 vote


3 other answers

Permanent link
Hi Luca,
The following code snippet should get you started:

com.ibm.team.workitem.common.model.IAttributeHandle handle = workItem.getCustomAttributes().get(0);
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) teamRepository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println("The attribute id: " + attribute.getIdentifier());
System.out.println("The attribute name: " + attribute.getDisplayName());
System.out.println("The value of the custom attribute: " + workItem.getValue(attribute));

1 vote

Comments

Hi Lauren, your code is fine, but in order to get a teamRepository, I need to import the com.ibm.team.repository.client package. Instead, I am writing a server-side extension, so I can use only "common" and "service" packages. Any suggestion?


Permanent link
Jared, it works!
Thanks for your answer!

0 votes


Permanent link
That worked for me too. Thank you very much. I have one question: I have a custom datefield which is a timestamp. When I try to set its value by using Plain Java libraries and java.sql.Timestamp object, there's no problem. But when I try to do the same operation in server side I get the error below.

Problem
An unhandled exception occurred during "Date Check Advisor".

java.sql.Timestamp incompatible with com.ibm.team.repository.common.IItemHandle

The Java code:

String str_date =

"11-June-13";

DateFormat formatter;

Date date =

new Date();

formatter =

new SimpleDateFormat("dd-MMM-yy");

try {

date = (Date) formatter.parse(str_date);

}

catch (ParseException e) {

}

java.sql.Timestamp timeStampDate =

new Timestamp(date.getTime());

newWorkItem.setValue(attribute, timeStampDate);


0 votes

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,953

Question asked: Sep 11 '12, 11:26 a.m.

Question was seen: 8,812 times

Last updated: Oct 09 '12, 3:50 a.m.

Confirmation Cancel Confirm