Hi,
Below is a sample groovy script which adds build numbers to our custom field options.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
//def Category log = Category.getInstance("com.onresolve.jira.groovy")
CustomFieldManager customFldMgr = ComponentAccessor.getCustomFieldManager();
OptionsManager optionsManager = ComponentAccessor.getComponentOfType(OptionsManager.class)
CustomField customField = customFldMgr.getCustomFieldObjectByName("Affects Build")
//Build Number Start Number
int startIndex = 501
//Build Number End Number
int endIndex = 600
def manager = ComponentAccessor.getOptionsManager()
def fieldConfig = customField.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig()
for (int i = startIndex; i <= endIndex; i++) {
def opt = "V" + i.toString()
manager.createOption(fieldConfig, null, null, opt)
}
The existing options looks like V01, V02, V03 and so on till V500 in sequence of numbers
We used to add them manually from the configuration options of the custom field.
Now we need to add 100 more versions i.e. from V501 to V600. So we created the groovy script.
The problem is it does not add the options in the sequence.
For ex. I see V500, V510, V511, ..... V501 and so on. Notice the options are not in the order they were added by the script.
Sequence-Problem.png
Could you please help me in figuring out the problem?