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?
Community moderators have prevented the ability to post new answers.
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; }
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use OptionsManager. Find the FiledConfig and use createOption method!
List <FieldConfigScheme> schemes = fieldConfigSchemeManager.getConfigSchemesForField(customField); FieldConfig config = fieldConfigScheme.getOneAndOnlyConfig();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.