Version
Jira v8.4.2, Scriptrunner 6.0.2-p5
Scenario
Drop down menu with four options, if value "Standard change" is selected, another drop down menu should be shown, being mandatory as well. Drop down menu should be shown immediately (client side scripting).
What I have tried
Totally newbie to Scriptrunner. I have tried to implement this using a Behaviour. Reading Scriptrunner doc, Behaviours Java-Script based it says "...Behaviours rely on client-side javascript.....However, the typical use cases are to prompt the user that they should be entering another field depending on some condition, or to hide a field for clarity’s sake. In these cases, the user is better off with behaviours, and no worse off than they were without them."
I did first try to implment the below script as "Server side script", but then guessing "Initialiser" is what I needed. But now also realizing that maybe Initalizer is "to early" and "server side" is to late?
The script (compiled from various sources using Google)
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.Field
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
final String parentDropDownFieldName = "CM Change type category"
final String childDropDownFieldName = "CM Standard Change Types"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def parentDropDownFieldNameFields = customFieldManager.getCustomFieldObjectsByName(parentDropDownFieldName)
def CustomField parentDropDownFieldNameCustomField = parentDropDownFieldNameFields.iterator().next()
def childDropDownFieldNameFields = customFieldManager.getCustomFieldObjectsByName(childDropDownFieldName)
def CustomField childDropDownCustomFieldNameField = childDropDownFieldNameFields.iterator().next()
log.debug("Show parentDropDownFieldNameField" + parentDropDownFieldNameCustomField)
def selectedOption = underlyingIssue.getCustomFieldValue(parentDropDownFieldNameCustomField).toString()
def isStandardSelected = selectedOption == "Standard Change"
def childDropDownMenuField = getFieldById(childDropDownCustomFieldNameField.id)
log.debug("The fieldName='" + parentDropDownFieldName + "' with fieldId='" + parentDropDownFieldNameCustomField.id + "' has value=" + selectedOption + " and therefore isStandardSelected=" + isStandardSelected)
Issue issue = event.issue
log.debug("Value of event=" + event)
log.debug("Value of issue=" + issue)
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.name == parentDropDownFieldName}
log.debug("Value of change=" + change)
if (change && isStandardSelected) {
def changeHolder = new DefaultIssueChangeHolder()
log.debug("Make field '" + childDropDownFieldName + "' visible")
childDropDownMenuField.setHidden(false)
childDropDownMenuField.setRequired(isStandardSelected)
} else {
log.debug("Make field '" + childDropDownFieldName + "' hidden")
childDropDownMenuField.setHidden(true)
childDropDownMenuField.setFormValue(null)
childDropDownMenuField.setRequired(isStandardSelected)
}
I am a bit confused about the event.issue-part, since I get the error
groovy.lang.MissingPropertyException: No such property: event for class:
Realizing that I am a bit lost