Page tree
Skip to end of metadata
Go to start of metadata
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
import org.apache.log4j.Logger

// Set log level
def log = Logger.getLogger(getClass())
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)
}

  • No labels