It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Implementing configurable customfields that respect customfield context

One of my mistakes while developing custom field was not to respect custom field context.

Assume we are implementing a Location custom field type and we want this custom field to be configurable (e.g. countries drop down).

We can design a servlet in which we can select the custom field and pick a country from the drop down. This would work when you create Location types custom fields which do not differ against custom field context.

As an example,

  • define UK Location custom field and select United Kingdom as the location.
  • define USA Location custom field and select United States as the location.

The code would be as below. It is getting customfieldId as the identifier.

LocationConfigItem config = locationService.getLocationConfig(customfieldId);

But if want to have only one location custom field, but differs based on custom field context?

  • define Location custom field
  • add context for UK issue types and select United Kingdom as the location
  • add context for USA issue types and select United States as the location

Our servlet would not work because it can be configured against custom field instead of custom field config context.

So, we should store fieldConfigId for the identifier in order to respect custom field contexts.

LocationConfigItem config = locationService.getLocationConfig(fieldConfigId);

We can obtain fieldConfigId by passing issue object to customfield's getRelevantConfig method as below

Long fieldConfigId = customField.getRelevantConfig(issue).getId();

This way, our configurable custom field type respects custom field contexts which means it can be configured per each context.

I hope I was clear, enjoy!

 

0 comments

Comment

Log in or Sign up to comment
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you