Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Setting up a scriptrunner behavior and need to add "Unknown" to a filtered version list

Corey Leighton February 14, 2018

I have behaviors that filter a project's version list based on the selection of a product custom field.  I can populate the list of versions properly, but I want to allow for a blank selection, similar to the "Unknown" option on the non-modified version list.  I want to give users the ability to zero out the version field.  And I would also like it to be the first option as when I edit an issue that hasn't had that version set, it'll populate it with the first version on the list (not cool).

The versions are in a collection :

Collection<Version> prodVersions = versions.findAll{Version version -> version =~ /^06\.03.*[\d]$|^0[7-8].*[\d]$|^Not.*|^0[6-8].*Patch$|^0[6-8].*Pack$/ }

How do I slap a "None" or blank or Unknown at the top of that Collection?

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Corey Leighton September 21, 2021

I figure I'll answer my own question here so I can serve as a warning to others... but to get that blank, 'Unknown' entry, I don't do it directly to a list of versions.... because that 'Unknown' value in the UI is backed up by an entry with an id of -1..  and you can't add an invalid version to a Collection<Version>.

So instead:

Collection<Version> prodVersions = [...]
Map<Long, String> versionFieldOptions = [(-1L): "Unknown"] // This seeds the map and creates that initial, blank entry in the UI
prodVersions?.each { versionFieldOptions.put(it.id as Long, it.name) }
someVersionFormfield.setFieldOptions(versionFieldOptions)
TAGS
AUG Leaders

Atlassian Community Events