Hello Team,
I am trying to automatically create multiples issues based on the selected options from a multi select custom field.
Please find my code below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
int i = 0
//assuming this is a multiple select list custom field
def suppliers = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_13401')
def selectedSuppliers = issue.getCustomFieldValue(suppliers) as Collection
def issueSummary = issue.summary
def issueDescription = issue.description
def issueReporter = issue.reporter
selectedSuppliers.each {
def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def newIssue = issueFactory.cloneIssue(issue)
newIssue.setIssueTypeId("11800")
newIssue.setSummary(issueSummary)
newIssue.setDescription(issueSummary)
newIssue.setReporter(issueReporter)
newIssue.setCustomFieldValue(suppliers, it.toString())
Map<String,Object> newIssueParams = [issue:newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
}
Unfortunately I am getting this error:
Please help!!
2018-08-21 16:30:01,878 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2018-08-21 16:30:01,880 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CR-425, actionId: 471, file: <inline script>
com.atlassian.jira.exception.CreateException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:588)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:494)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:599)
at com.atlassian.jira.issue.managers.RequestCachingIssueManager.createIssueObject(RequestCachingIssueManager.java:198)
at com.atlassian.jira.issue.IssueManager$createIssueObject$2.call(Unknown Source)
at Script279$_run_closure1.doCall(Script279.groovy:26)
at Script279.run(Script279.groovy:14)
Caused by: com.atlassian.jira.workflow.WorkflowException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:766)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:580)
... 6 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39)
at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693)
at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:81)
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1014)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1407)
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606)
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:742)
... 7 more