Language:

Tip of the Week: How to Get a CustomField

Oct 21, 2016
Aleks Zuevich

Posted by Aleks Zuevich

How to properly get an instance of a customField in java? There are some methods in CustomFieldManager interface to get CustomField by ID, text key or even by a certain customFieldName. However, this approach has some disadvantages as you need to know the ID or the key, which depends on the JIRA instance so you don’t know it during the plugin development, and you might change the name later.

The solution that we propose is to use typesafety approach with instanceof java operator:

This way we get the list of all CustomFields, then test every customField if it has the given custom type (the suggestion is there is one CustomField of the given type). In this case, we also use TreeComponentField – the extension of GenericTextCFType, describing our CustomField behavior.

I hope this advice will help to make your JIRA work even better for your team! If you have any questions – please, don’t hesitate to contact us and we will do our best to help you.

Share this post on:

CONTACT US

We are always ready to help you