Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do you add custom field options in a plugin?

Nick Seegmiller January 9, 2013

I'm currently trying to write a plugin for JIRA that, among other things, will add options to a Multi-Select type custom field I have based on data in an external database. I can't for the life of me figure out where, if at all, in the SDK I can add a new option to the custom field.

Basically, we have a field that is a multi-select list of our customers and I need to add new options to the field when we add customers into our CRM. Is this possible to do via the SDK or do I need to directly write to the database?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 9, 2013

The API definitely - if you add via SQL in the database, you need to stop Jira while you do it...

This might help. It's for v4, but I don't think the principles have changed much - create an "option" object and add it to the custom field. Note that I only needed this for the default/global context, you'll need to expand on the config-scheme bit if you need to use contexts.

public Option addSelectValue(String value, CustomField cf)
    {

    	long numberAdded = 0 ;
    	//System.out.println ("Try to add: " + value );
    	OptionsManager optionsManager = ManagerFactory.getOptionsManager() ;

    	Option newOption = null;

        if (cf != null)
        {
            List schemes = cf.getConfigurationSchemes();
            if (schemes != null && !schemes.isEmpty())
            {
                FieldConfigScheme sc = (FieldConfigScheme) schemes.get(0);
                Map configs = sc.getConfigsByConfig();
                if (configs != null && !configs.isEmpty())
                {
                    FieldConfig config = (FieldConfig) configs.keySet().iterator().next();
                    newOption = optionsManager.createOption(config,
                                                            null,
                                                            new Long(numberAdded),
                                                            value);
                    numberAdded++;
                    optionsManager.getOptions(config).sortOptionsByValue (null);
                }

            }
        }
        //System.out.println ("Should have added: " + newOption.getValue() );
        return newOption;
    }

Nick Seegmiller January 10, 2013

As soon as I saw this I felt a little bit stupid as I swear I've done this before. Still not sure why I couldn't seem to find this in the docs; I was fully convinced there was an OptionsManager class. Oh well. Either way, thanks for the help. Both of you.

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2013

Use OptionsManager. Find the FiledConfig and use createOption method!

List <FieldConfigScheme> schemes = fieldConfigSchemeManager.getConfigSchemesForField(customField);
FieldConfig config = fieldConfigScheme.getOneAndOnlyConfig();

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 9, 2013

The API definitely - if you add via SQL in the database, you need to stop Jira while you do it...

This might help. It's for v4, but I don't think the principles have changed much - create an "option" object and add it to the custom field. Note that I only needed this for the default/global context, you'll need to expand on the config-scheme bit if you need to use contexts.

public Option addSelectValue(String value, CustomField cf)
    {

    	long numberAdded = 0 ;
    	//System.out.println ("Try to add: " + value );
    	OptionsManager optionsManager = ManagerFactory.getOptionsManager() ;

    	Option newOption = null;

        if (cf != null)
        {
            List schemes = cf.getConfigurationSchemes();
            if (schemes != null && !schemes.isEmpty())
            {
                FieldConfigScheme sc = (FieldConfigScheme) schemes.get(0);
                Map configs = sc.getConfigsByConfig();
                if (configs != null && !configs.isEmpty())
                {
                    FieldConfig config = (FieldConfig) configs.keySet().iterator().next();
                    newOption = optionsManager.createOption(config,
                                                            null,
                                                            new Long(numberAdded),
                                                            value);
                    numberAdded++;
                    optionsManager.getOptions(config).sortOptionsByValue (null);
                }

            }
        }
        //System.out.println ("Should have added: " + newOption.getValue() );
        return newOption;
    }

TAGS
AUG Leaders

Atlassian Community Events