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?
Hi, strange indeed. It seems there is some parallelism...
I guess the parameter "sequence" is there to handle the order so... I would just add your iterator ( i ) as sequence ?
Yup. Adding the sequence works. But I had to go to database and check sequence number.
In our case for V500 has the sequence number of 499. So for us it is (i -1) as the sequence number.
Thanks Marc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Marc.
In our case the items are not sorted alphabetically. Otherwise after V10, we would have seen V101.
When we add them manually, we don't specify the sequence. It adds automatically to the bottom of the list. So I don't want to specify the sequence. The sequence in which we add, the same should be visible on GUI.
Is for loop running in parallel somehow?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think by default items are ordered alphabetically ? But the third parameter of the createOption method allows you to specify the sequence!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.