Example scripts
To homepage
Jira

Check if Checkbox Contains a List of Wanted Values
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.0 - 8.14)

ScriptRunner For Jira (6.18.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import org.apache.log4j.Level
// Set log level
log.setLevel(Level.DEBUG)
final fieldName = 'CheckBoxA'
final wantedOptions = ['Yes', 'No']
def customFieldManager = ComponentAccessor.customFieldManager
def checkBoxFieldA = customFieldManager.customFieldObjects.find { it.name == fieldName }
// If checkbox field does not exist, it is not needed to continue
if (!checkBoxFieldA) {
return
}
def checkBoxFieldAValue = issue.getCustomFieldValue(checkBoxFieldA)
// If checkbox does not contain values, it is not needed to continue
if (!(checkBoxFieldAValue in List)) {
return
}
def selectedOptions = checkBoxFieldAValue?.collect { (it as LazyLoadedOption).value }
def containsAllWanted = selectedOptions.containsAll(wantedOptions)
log.debug("""
selected Options string list = $selectedOptions
Boolean check if contains wanted = $containsAllWanted
""")
if (containsAllWanted) {
// Run the logic that you want to run when the checkbox fields contains all wanted values here
// For example, all check box options that were selected can be cleared
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
issue.setCustomFieldValue(checkBoxFieldA, null)
// If you use this as a post-function and place it before the default "Update change history for an issue and store
// the issue in the database" Jira post-function the following line is not needed.
ComponentAccessor.issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Having an issue with this script?
Report it here