You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!


Validate the Organizations field


This behaviour is used to validate the Service Desk's Organizations field while creating or editing an issue.


This behaviour makes a call to the REST endpoint using the sample code. Once the values are obtained from the REST endpoint, they are stored in a map. Next, the IDs of organizations selected from Organizations field will be used to get the values from the map. Once the values are obtained from the map, the characters used in the map values (the organizations' names) are validated to check if they meet the conditions set.


  • Jira Service Desk Jira Service Desk (4.0 - 4.21)
  • ScriptRunner for Jira ScriptRunner for Jira (6.41.0)
import com.onresolve.jira.groovy.user.FieldBehaviours import groovy.json.JsonSlurper import groovy.transform.BaseScript @BaseScript FieldBehaviours behaviours def organization = getFieldById(fieldChanged) def organizationValue = organization.formValue as List organization.clearError() //Specify the Service Desk's ID final def serviceDeskId = '' final def host = applicationProperties.getString('jira.baseurl') final def restEndpointName = 'getOrganizations' def baseUrl = "${host}/rest/scriptrunner/latest/custom/${restEndpointName}?serviceDeskId=${serviceDeskId}" def response = baseUrl.toURL().text def json = new JsonSlurper().parseText(response) as Map organizationValue.each { def output = json[it].toString() //Validate characters used in the String if (!Character.isLetter(output.charAt(0)) || !Character.isLetter(output.charAt(1)) || !Character.isDigit(output.charAt(2)) || !Character.isDigit(output.charAt(3)) || !Character.isDigit(output.charAt(4)) || output.charAt(5).toString() != '_') { organization.setError("Invalid Characters Used") } }
Discovered an issue? Report it here