23 Mar 2015
Accessing Field Configurations in JIRA for changing field description

Accessing Field Configurations in JIRA for changing field description

Field configuration defines behavior of all standart (system) fields and custom fields available in JIRA installation.

Each field in field configuration has:

  • description that appears under the field when an issue is edited,
  • visibility rule of the field,
  • option whether the field is required or optional,
  • renderer for text fields.

Field configurations allow to make configurations of fields for projects to have different behaviour in these projects.

Sometimes a field should have the same behaviour in all projects, but going through all of them manually is uncomfortable process. So it can be automated by using JIRA API. The example is changing description of a field for all projects.

 

Task: change the description in a custom field.

Solution: To change the description of the custom field we need to get a custom field object, change the description and update this object.

CustomFieldManager fieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = fieldManager.getCustomFieldObjectByName("My Field");
customField.setDescription("New description");
fieldManager.updateCustomField(customField);

But this works only if the field is not linked to the custom Field Configurations.

To change the description of a custom field in Default Field Configuration:

EditableDefaultFieldLayout defaultFieldConfiguration = 
ComponentAccessor.getFieldLayoutManager().getEditableDefaultFieldLayout();

List<FieldLayoutItem> fields = defaultFieldConfiguration.getFieldLayoutItems();

for (FieldLayoutItem field : fields) {
if (item.getOrderableField().getId().equals(customField.getId())) {
defaultFieldConfiguration.setDescription(field, "New description");
}
}

ComponentAccessor.getFieldLayoutManager().storeEditableDefaultFieldLayout(layout);

To change the description of a custom field in all custom Field Configurations:

List<EditableFieldLayout> fieldConfigurations = 
ComponentAccessor.getFieldLayoutManager().getEditableFieldLayouts();

for (EditableFieldLayout fieldConfiguration : fieldConfigurations) {
List<FieldLayoutItem> fields = fieldConfiguration.getFieldLayoutItems();

for (FieldLayoutItem field : fields) {
if (field .getOrderableField().getId().equals(customField .getId())) {
fieldConfiguration.setDescription(field, "New description");
}
}

ComponentAccessor.getFieldLayoutManager().storeEditableFieldLayout(fieldConfiguration);
}

In this way fields can be managed.

Similar posts:


Favourite posts

What it Takes to Get an e-Commerce Site Online

Getting an e-Commerce website online might sound like a huge undertaking,...

WebView Interactions with JavaScript

WebView displays web pages. But we are interested not only in web-content...

Google Maps API for Android

Google Maps is a very famous and helpful service, which firmly entrenched...

Unit Testing with RSpec

RSpec is an integral part of Test Drive Development (TDD) and its main id...

Client side JavaScript: Knockout in practice

When developing a web application that extensively works with user input ...

Accessing Field Configurations in JIRA for changing field description

Field configuration defines behavior of all standart (system) fields and ...

A Guide for Upgrading to Ruby on Rails 4.2.0

As you might have already heard, the latest stuff for upgrading rails was...