We recently upgraded from jira 6.3.1 to 7.1.10, incremental updates as specified. we have a Validator script on the create that makes Multi-Level Cascading Select drop-down fields mandatory, this is no longer mandatory
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import org.apache.log4j.Category
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.fields.CustomFieldImpl
def log = Logger.getInstance("com.onresolve.jira.groovy.Validator")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug("********************************** Service Group Selector Validator ***********************************************")
//ComponentManager componentManager = ComponentManager.getInstance()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Service Group Selector")
log.debug("Obtained Service Group Selector custom field")
def myIssue = issue
Map cfVal = myIssue.getCustomFieldValue(cf) as Map
log.debug("Converted field to map")
String first = cfVal.get(0)
String second = cfVal.get(1)
String third = cfVal.get(2)
log.debug("Service Group Validator: " + first)
log.debug("Service Name validator: " + second)
log.debug("Service Category validator: " + third)
def matchString = 'com.sourcesense.jira.plugin.customfield.option.SpecialOptionFactory$SpecialOption@0'
if ((first == matchString) || (third == matchString) || (second == matchString))
{
log.debug("Invalid options selected for service category")
log.debug("raising exception")
InvalidInputException invalidInputException = new InvalidInputException("Service Group Selector")
invalidInputException.addError("Service Group Selector", "You must fill out all the Service Group Selector field values")
throw invalidInputException
}
log.debug("Valid options selected for service category")
Error:
it fails after the 'Converted field to map'
Script function failed on issue: null, actionId: 1, file: serviceGroupValidator.groovy
I assume that by "this is no longer mandatory", you mean that the validator just isn't validating the way you'd expect.
This may well be an API change in the Multi-Level Cascading Select plugin. I noticed from their version history that there's a compatibility break between 3.2 (which works with JIRA 6) and 4.0 (which works with JIRA 7).
They've even got some ScriptRunner examples in their docs, with different code for JIRA 6 and 7.
Assuming that you just want to check that they've filled in every level, I think you could do this:
import com.atlassian.jira.component.ComponentAccessor import com.opensymphony.workflow.InvalidInputException log.debug("********************************** Service Group Selector Validator ***********************************************") def customFieldManager = ComponentAccessor.getCustomFieldManager() def cf = customFieldManager.getCustomFieldObjectByName("Service Group Selector") log.debug("Obtained Service Group Selector custom field") def myIssue = issue def cfVal = myIssue.getCustomFieldValue(cf) boolean passes = cfVal.any{ it.toString() == 'com.sourcesense.jira.plugin.customfield.option.SpecialOptionFactory$SpecialOption@0' } if (!passes) { log.debug("Invalid options selected for service category") log.debug("raising exception") InvalidInputException invalidInputException = new InvalidInputException("Service Group Selector") invalidInputException.addError("Service Group Selector", "You must fill out all the Service Group Selector field values") throw invalidInputException } log.debug("Valid options selected for service category")
Or, following their example:
import com.atlassian.jira.component.ComponentAccessor import com.opensymphony.workflow.InvalidInputException log.debug("********************************** Service Group Selector Validator ***********************************************") def customFieldManager = ComponentAccessor.getCustomFieldManager() def cf = customFieldManager.getCustomFieldObjectByName("Service Group Selector") log.debug("Obtained Service Group Selector custom field") def myIssue = issue def cfVal = myIssue.getCustomFieldValue(cf) boolean passes = cfVal.any{ it.toString().startsWith('com.sourcesense.jira.plugin.customfield.option.SpecialOptionFactory') } if (!passes) { log.debug("Invalid options selected for service category") log.debug("raising exception") InvalidInputException invalidInputException = new InvalidInputException("Service Group Selector") invalidInputException.addError("Service Group Selector", "You must fill out all the Service Group Selector field values") throw invalidInputException } log.debug("Valid options selected for service category")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.