Blog post

Tip of the Week: How to Get a CustomField

Home    —    Blog    —    Tip of the Week: How to Get a CustomField
Aleks Zuevich
Posted by Aleks Zuevich
October 21, 2016

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:

CustomField treeComponentField = null;
for (CustomField customField : ComponentAccessor.getCustomFieldManager()
    .getCustomFieldObjects()) {
    if (customField.getCustomFieldType() instanceof TreeComponentField) {
        treeComponentField = customField;
        break;
    }
}

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.

Other services by Polontech

Services

Atlassian migration

To Server. To Cloud. To Data Center. Server to Server. Cloud to Cloud. To Atlassian.
go to page
Services

Atlassian configuration

Jira Software. Confluence. Jira Service Desk. Atlassian addons. Custom scripting.
go to page
Services

Training

Fast start. Agile. ITSM. Atlassian.
go to page
Services

Support

Technical support 24/7. Health check. Upgrade. Data protection. Managed Services.
go to page
Services

Installation

Choosing Atlassian products. Atlassian product at your service. Installing Atlassian in the cloud or server...
go to page
Services

Consulting

Audit. Jira Add-ons. Agile. ITIL/ITSM. User management. Team collaboration. Asset management...
go to page
Services

Hosting

Migration to Atlassian Cloud. Private cloud. Public cloud.
go to page
Services

Portfolio management

Audit. Design. Launch. Support.
go to page
Services

Licensing

Buying. Renewal. Managed licenses.
go to page
Services

CI/CD + DevOps

DevOps strategy. Commit. Build. Test. Deploy.
go to page

Use form to contact us