Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Behavior hides (none) option - how could it show

Hello,

 

We have a Behavior (scriptrunner) that shows only certain values in a select list field when certain other values are chosen in a different select list field:

 

Here is the script:

 

def RespProject = getFieldByName("Responsible Project")
def AgileTeam = getFieldByName("Agile Team")

def customField = customFieldManager.getCustomFieldObject(AgileTeam.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

if (RespProject.getValue() as String == "FC Audio") {

def optionsMap = options.findAll {
it.value in ["VSP", "VST", "Aud_Decibels", "None"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
AgileTeam.setFieldOptions(optionsMap)
}

else if (RespProject.getValue() as String == "FC Connectivity") {

def optionsMap = options.findAll {
it.value in ["DCON_Fermi", "None"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
AgileTeam.setFieldOptions(optionsMap)
}

 

 

However, I cannot make it still allow the selection of the "None" option. It automatically selects the first value in the list, and sometimes we just want to have a value selected in "Responsible project", but the "Agile Team" can still be empty, until an analysis is made.

 

Thank you!

1 answer

1 accepted

2 votes
Answer accepted

"None" is not really an "option", but if you add either [null: "None"] or  ["-1": "None"] to your optionsMap it should work. Basically, try

AgileTeam.setFieldOptions(optionsMap +  ["-1": "None"] )
Payne Community Leader Jul 12, 2019

I do a similar thing in a Behaviour and add a key/value pair of empty strings, i.e. ["":""]

Like Ilya Turov likes this

Thank you very much, it works!

For me, on Jira 7.9.2 and Scriptrunner 6.3.0, I got a 'static type checking' error by following the above example. 

I solved the error by type-casting the added Option, like so:

accountType.setFieldOptions(selectAvailableOptions + (Option) ["-1": "None"])

Added import statement: 

      import com.atlassian.jira.issue.customfields.option.Option

klosote I'm New Here Apr 09, 2021

Hi, I tested all your options specially the (Option) ["-1": "None"] and i got the following error on JIRA 8.13:

Is there any other way to do it?

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{-1=None}' with class 'java.util.LinkedHashMap' to class 'com.atlassian.jira.issue.customfields.option.Option' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.customfields.option.Option(LinkedHashMap)

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you