Following is my script listener to update a custom field called "Application" which is a multi-select field. On issue create event, if the issue summary contains the word JIRA, am trying to set the application field dropdown value to JIRA. Here is the code and the listener executes without an error BUT the field isn't getting updated in the issue create event, but when the issue summary is updated, then the listener throws an error.
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Application")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = event.issue as MutableIssue
def summary = issue.summary
if (issue.summary == "jira")
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Error log when issue summary is updated.
2021-04-12 09:03:19,368 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2021-04-12 09:03:19,369 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
at com.atlassian.jira.issue.IssueManager$updateIssue$1.call(Unknown Source)
It's this line:
You can't just jam a string into a field unless it's a field that holds strings (short and long text).
You have two problems here - first, a select list holds options, not strings, and second, a multi-select is a collection of options, not a single option (even if there's only one value, it's still a collection.
What you should probably be doing is:
https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console is a good base for seeing how to handle all the different types of field. Obviously, you can concentrate just on the multi-select bits.
Hello Atlassian Community! We’re thrilled to announce some exciting changes to incident management in Jira Service Management Cloud, in order to give your teams extra muscle during incidents, and ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events