Hi, I'm using Jira Software Server: 8.5.0 and Scriptrunner: 6.15.0. On the create issue post-function, I want to read a cascading select list parent value (first value) and based on that value set a single select list value.
Cascading select list: "Area Affected"
Parent: Electrical Child: 1, 2, 3 e.g. Electrical - 1, Electrical - 2
Parent: Facilities Child: A, B, C e.g. Facilities - A, Facilities - B
Parent: Other Child: X, Y, Z
Single select list: "Team" Options: redTeam, blueTeam, greenTeam
When submitter chooses Electrical - whatever, Team automatically sets to redTeam
I'm stuck on getting just the parent value. Examples I've found are only snippets or outdated and no longer function. I found this code and got it to work (temporarily hard coded an issue for easy troubleshooting):
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("REQ-32")
if(issue){
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectsByName("Area Affected")
def cFieldValue = issue.getCustomFieldValue(cField[0])
return cFieldValue
}
Console Result: [null:Facilities, 1:A]
But I can't figure out how to adjust the code to break out the parent/child values. Adding this (and other variations with maps, etc.) hasn't worked:
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.option.Option
CustomFieldParams params = (CustomFieldParams) cFieldValue;
if (params != null) {
Object parent = params.getFirstValueForNullKey();
Object child = params.getFirstValueForKey("1");
Any help would be greatly appreciated. Eventually, once I get the parent value, I'll set the single select list:
// Set single select list = Facilities
if (parent == ["Facilities"]) {
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Team")
def cfConfig = cfSelect.getRelevantConfig(issue)
def newValue = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == 'redTeam'
}
issue.setCustomFieldValue(cfSelect, newValue)
}
Thanks in advance.