I am trying the below script to create multiple issues based on options selected. One issue for each option selected. Also, the link should be created with the source issue.
The script is creating only one issue with no links created. Can anyone help here?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.MutableIssue
Issue issue = (Issue) transientVars.get("issue");
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.customFieldManager
def cf = customFieldManager.getCustomFieldObjectByName("Multiselect")
def summariesList = (issue.getCustomFieldValue(cf) as Collection<Option>)*.value
def issueSummary = issue.summary
def issueDescription = issue.description
def issueReporter = issue.reporter
summariesList.each { Multiselectvalue ->
def issueFactory = ComponentAccessor.getIssueFactory()
MutableIssue newIssue = issueFactory.getIssue()
newIssue.setSummary(Multiselectvalue)
newIssue.setPriorityId(constantManager.getPriorities().find {
it.getName() == "High"
}.id)
newIssue.setProjectObject(issue.getProjectObject())
newIssue.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Story"
}.id)
newIssue.setDescription(issueSummary)
newIssue.setReporter(issueReporter)
newIssue.setCustomFieldValue(cf ,Multiselectvalue.toString())
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
def issueLinkManager = ComponentAccessor.getComponent(IssueLinkManager);
issueLinkManager.createIssueLink((Long)newIssue.getId(), (Long)issue.getId(), (Long)10001, (Long)1, currentUser)
}
Many thanks!