It's all about the answers!

Ask a question

Getting custom attributes names via Java API

Luca Martinucci (962278108) | asked Sep 11 '12, 11:26 a.m.
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)?

Accepted answer

permanent link
Jared Russell (1.3k12019) | answered Sep 12 '12, 6:16 a.m.
 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

3 other answers

permanent link
Lauren Hayward Schaefer (3.3k11427) | answered Sep 11 '12, 11:57 a.m.
Hi Luca,
The following code snippet should get you started: handle = workItem.getCustomAttributes().get(0); 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));

Luca Martinucci commented Sep 12 '12, 6:07 a.m.

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

permanent link
Luca Martinucci (962278108) | answered Sep 12 '12, 9:45 a.m.
Jared, it works!
Thanks for your answer!

permanent link
Canberk Akduygu (99237271) | answered Oct 09 '12, 3:50 a.m.
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.

An unhandled exception occurred during "Date Check Advisor".

java.sql.Timestamp incompatible with

The Java code:

String str_date =


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

Your answer

Register or to post your answer.