How do I identify disabled options in a select list from scriptrunner?

Andy Hurley April 30, 2019

I have a checkbox list where some of the options have been disabled and I need to be able to see if a user has checked all the options.

I was just counting the options the user has selected vs how many are on the list:

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("User Sign-off")
def options = ComponentAccessor.getOptionsManager().getOptions(cf.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig())
def values = issue.getCustomFieldValue(cf)

if (options && values) {
if (options.size() == values.size()) retval = "True"
}

 

But this fails due to the disabled options. I can't seem to be able to tell which options are disabled and which are not. I think I am going to have to iterate over all the (not disabled) options and make sure that the user has selected them but I am stuck as I can't seem to be able to find the disabled status of each option.

I'm sure it should be simple - I've found ways to disable options but not to see if they are disabled.

1 answer

1 accepted

1 vote
Answer accepted
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 30, 2019

Hello @Andy Hurley 

You can get not disasbled options like this

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("User Sign-off")
def options = ComponentAccessor.getOptionsManager().getOptions(cf.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig()).findAll {!it.disabled}
def values = issue.getCustomFieldValue(cf)

if (options && values) {
if (options.size() == values.size()) retval = "True"
}
Andy Hurley April 30, 2019

Ah thanks! That's the secret, the disabled method - odd I could not find that.

I am using the following now in case anyone else needs to do similar (there's probably a neater way but my js is rather limited:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue

def retval = "True"
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("User Sign-off")
def options = ComponentAccessor.getOptionsManager().getOptions(cf.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig()).findAll {!it.disabled}
def values = issue.getCustomFieldValue(cf).toString()


for (String opt : options)
{
if (!values.contains(opt)) retval = "False"
}

return retval

 

I feel like the for loop should not be needed but I wanted to take care that every enabled option has a corresponding tick in the issue, allowing for old options that may have been ticked but now disabled so a simple count is not sufficient.  

Srikanth Ganipisetty March 3, 2022

Hi @Andy Hurley @Mark Markov 

How can we use this scripts to pull only disabled options on the given custom field? 

Thanks,

Srikanth Ganipisetty

Srikanth Ganipisetty March 3, 2022

@Andy Hurley  or @Mark Markov 

I'm seeing this error at issue.getCustomFieldValue(cf) line at your scripts

java.lang.NullPointerException: Cannot invoke method getConfigurationSchemes() on null object at Script30448844.run(Script30448844.groovy:7)

What should be the resolution? 

Thanks,

Srikanth Ganipisetty

Suggest an answer

Log in or Sign up to answer