Hello, Jira's built-in single select picker does not support both value and label properties so I am attempting to use ScriptRunner's Custom Picker (https://docs.adaptavist.com/sr4js/latest/features/script-fields/built-in-script-fields/custom-picker) to create a very simple select that does this, however I am having some trouble because all examples use either an API or a DB connection to populate the list of options.
Perhaps this is not even the right way to approach this issue, suggestions?
I am not very familiar with Groovy but here is pseudo-code of what I am trying to accomplish:
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
def options = [
{class: 'Foo', description: 'Bar'},
{class: 'Baz', description: 'Qux'},
{class: 'Quux', description: 'Corge'},
]
toOption = { Map<String, String> map, Closure<String> highlight ->
new PickerOption(
value: map.class,
label: map.description,
html: highlight(map.description, false),
)
}
I don't have much experience with the custom pickers, but looking the the offered "Version picker" snippets I was able to construct a working sample:
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
import org.apache.commons.lang3.StringUtils
def options = [
[id: 'Foo', description: 'Bar'],
[id: 'Baz', description: 'Qux'],
[id: 'Quux', description: 'Corge']
]
search = { String inputValue ->
options.findAll {
StringUtils.containsIgnoreCase(it.description, inputValue)
}
}
getItemFromId = { String id ->
options.find { it.id == id }
}
toOption = { Map<String, String> option, Closure highlight ->
new PickerOption(value: option.id,
label: option.description,
html: "${highlight(option.description, false)} (${option.id})"
)
}
renderItemViewHtml = { Map<String, String> option ->
"$option.description ($option.id)"
}
renderItemTextOnlyValue = { Map<String, String> option ->
option.description
}
The main change from your pseudo code is the correct square braces for initializing a map object and avoiding using "class" as key for a map. Since class in groovy can be confused as a shortcut for the getClass() method.
With this example, you can define whatever as your list of options in the options (functionally a List<Map<String, String>> but def work just fine).
You can change the interpolated stings in renderItemViewHtml and pickerOption.html to combine the id/description differently (including hiding the id completely if that's your preference). Remember tho that the "id" value is what will be stored in the DB. But the description will be stored in the Index and fetched in real-time when you access the issue.
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.