Hi,
I have a working REST endpoint script which allows me to reload a very large number of single select options. This is required to periodically reload options which come from an external SAP system and contains many thousands of options. The script is executed from within an Excel spreadsheet and performs these functions for a single select custom field:
1. Disable all existing options
2. For each row in the spreadsheet:
a. Check if the existing option already exists in the select list.
b. If found, enable the option
c. If not found, add the option
3. Sort options
Now... I have a similar requirement for a cascading select. My problem is that while I can iterate through the parent level options, I can't see a way to iterate the child options. The code below only finds the parent option, the child options size is always 0 (the cascading select DOES have child options) and no child option is ever returned.
private Option getChildOption(List<Option> rootOptions, String value) {
for (Option parent : rootOptions) {
log.info("Parent=" + parent.getValue())
if (parent.getValue().equals(value)) {
List<Option> childOptions = parent.getChildOptions();
log.info("Child options size=" + childOptions.size())
for (Option child : childOptions) {
log.info("Child=" + child.getValue())
return child;
}
}
}
return null;
}
I can never wrap my head around for loops ... I'm so much more confortable with groovy methods.
Here is how I would write a function that takes a list of rootOptions and returns all the child values based on the supplied parent value:
import com.atlassian.jira.issue.customfields.option.Options
def getChildOptions(Options rootOptions, String parentValue){
def parentOption = rootOptions.find{it.value == parentValue}
if(parentOption){
parentOption.childOptions.collect{it.value}
}
}
Note the import. The OptionaManager.getOptions(fieldConfig) method returns this Options collection.
If you want to return the full child option objects and not just the string value, omit the colect{it.value} part.
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.