Hi, thanks in advance for anyone who can help me out, here. I have the following script:
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def fieldConfigSchemeManager = ComponentAccessor.getFieldConfigSchemeManager()
def cf = customFieldManager.getCustomFieldObjectByName("New Hire Account provisioning")
def config = fieldConfigSchemeManager.getRelevantConfig(issue, cf)
def allOptions = optionsManager.getOptions(config)
def checkboxFieldValues = cf.getValue(issue)
def cField = customFieldManager.getCustomFieldObject('customfield_15564')
def cFieldValue = issue.getCustomFieldValue(cField)
def cField2 = customFieldManager.getCustomFieldObject('customfield_16662')
def cFieldValue2 = issue.getCustomFieldValue(cField2)
log.error(checkboxFieldValues)
checkboxFieldValues.each { optionValue ->
log.error(optionValue)
log.error(optionValue.toString())
if ((optionValue.toString() == "Egencia") && ((cFieldValue == null) || (cFieldValue2 == null)))
throw new InvalidInputException("Manager Email", "Both Department Number and Manager Email are required when specifying an Egencia account be set up.")
}
---------------------
The idea is to loop through the values of a checkbox field, check that a specific value is checked and either/both of two other fields is null, and then throw an exception based on that. However, evidently I'm not pulling out the values of the checkboxes correctly, as the first log message gives me
2018-05-22 16:08:55,870 ERROR [workflow.ScriptWorkflowFunction]:
instead of a list of values, and the two log messages inside the each loop are never hit. I feel like I've tried every method on the web and NONE of them work for checkboxes - they either don't even pass a syntax check, or they don't produce any values.
Hi Maya,
Here is an example of how to get the selected values for a checkbox custom field for issue with key JRA-1
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("JRA-1")
def checkboxes = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find {it.name == "Checkboxes"}
def checkedValues = (checkboxes?.getValue(issue) as List <LazyLoadedOption>)*.value
assert checkedValues?.contains("Yes") //check if one of the selected values is 'Yes'
Hope that helps.
Regards, Thanos
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.