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.
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"
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How can we use this scripts to pull only disabled options on the given custom field?
Thanks,
Srikanth Ganipisetty
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.