I am creating a listener that is triggered by a new link being created. The listener is then attempting to create a new Issue which has a Cascading Select List field which should be populated. However this field is not being populated - despite the Listener executing without error.
Here is my code (trimmed to show only the issue creation):
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def cfm = ComponentAccessor.customFieldManager IssueManager issueManager = ComponentAccessor.getIssueManager() def optionsManger = ComponentAccessor.getOptionsManager()
Issue original_test = issueManager.getIssueObject('ABC-1')
Issue new_test= ComponentAccessor.getIssueFactory().getIssue() def getParentChildOptionsByValue(CustomField customField, Issue issue, String parentValue, String childValue) { def availableOptions = ComponentAccessor.optionsManager.getOptions(customField.getRelevantConfig(issue)) def rootOptions = availableOptions.getRootOptions() def parentOptionToSet = availableOptions.find { it.value == parentValue } def childOptions = rootOptions[0].getChildOptions() def childOptionToSet = childOptions.find { it.value == childValue } return [null: parentOptionToSet, "1": childOptionToSet] } new_test.setProjectId(original_test.getProjectObject().getId()) new_test.setIssueTypeId(original_test.issueType.getId()) new_test.setSummary("Revised Test") new_test.setReporterId(original_test.reporterId) new_test.setAssigneeId(original_test.assigneeId) new_test.setDescription(original_test.getDescription()) new_test.setCustomFieldValue( cfm.getCustomFieldObject(10450), getParentChildOptionsByValue( cfm.getCustomFieldObject(10450), original_test, "Specification Based", "Equivalence Partitioning" ) ) // Cascading select
log.debug("Cascading Select List before creation:\t"+new_test.getCustomFieldValue(10450).toString()) new_test = issueManager.createIssueObject(user, new_test)
log.debug(new_test.key) log.debug("Cascading Select List after creation:\t"+new_test.getCustomFieldValue(10450).toString())
And here is the log:
2025-04-11T14:16:15,037 DEBUG [runner.ScriptBindingsManager]: Cascading Select List before creation: [null:Specification Based, 1:Equivalence Partitioning] 2025-04-11T14:16:15,204 DEBUG [runner.ScriptBindingsManager]: No selected values found, terminating script execution. 2025-04-11T14:16:15,887 DEBUG [runner.ScriptBindingsManager]: PETM-40 2025-04-11T14:16:15,887 DEBUG [runner.ScriptBindingsManager]: Cascading Select List after creation: null
I am confused most by the 2nd line of the log. It is not output directly by my code but I am assuming it is due to the createIssueObject method failing to write the Cascading Select List but creating the issue regardless.
Can anyone help me understand why this is failing and what I can do to resolve this?
I suggest you to use HAPI from Scriptrunner instead.
// cascading select
12 setCustomFieldValue('CascadingSelect', 'BBB', 'B2')
Update the Value of Custom Fields through the Script Console
Regards
Hi @Florian Bonniec ,
Thanks for your reply. I tried using HAPI and managed to resolve my problem by making a slight tweak to the suggestion.
I first tried using:
new_test.update {
setCustomFieldValue('Test Design Technique', 'Specification Based', 'Equivalence Partitioning')
}
Which was giving the following error:
com.adaptavist.hapi.jira.issues.exceptions.IssueUpdateValidationException: The following errors occurred: (You can not update a null issue.)
at com.adaptavist.hapi.jira.issues.implementation.IssuesImplementation.update(IssuesImplementation.groovy:211)
at com.adaptavist.hapi.jira.extensions.IssueExtensions.update(IssueExtensions.java:71)
at Script92.run(Script92.groovy:64)
This was then resolved by changing update to set:
new_test.set {
setCustomFieldValue('Test Design Technique', 'Specification Based', 'Equivalence Partitioning')
}
Which allowed me to populate the field before creating the Issue. ref
Thanks again!
Sam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.