Hi guys,
I'm trying to create an issue and, according to a certain multi selection custom field (suppliers) I'd like to raise multiple issues of another issuetype. I mean:
Example:
Create issue (user story)
If supplier = "A" and "B"
Create issue (bug) for A
Create issue (bug) for B
Until now I am able to create them without any problem but as soon as I'd like to get the current value of the supplier, scriptrunner copies all the values instead of the current one.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.fields.NavigableField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
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_10201")
String selectedSuppliers = issue.getCustomFieldValue(suppliers)
def issueSummary = issue.summary
def issueDescription = issue.description
def issueReporter = issue.reporter
selectedSuppliers?.each {LazyLoadedOption it ->;
def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def newIssue = issueFactory.cloneIssue(issue)
newIssue.setIssueTypeId("10101")
newIssue.setSummary(issueSummary)
newIssue.setDescription(issueSummary)
newIssue.setReporter(issueReporter)
newIssue.setCustomFieldValue(suppliers, selectedSuppliers)
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
}
How can I point
newIssue.setCustomFieldValue(suppliers, selectedSuppliers)
to
selectedSuppliers?.each
?
More over, is it possible to link the newly created issues to the trigger one?
Cheers!