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!
selectedSuppliers is a list of all of the selected options from your multiselect, you need to use the 'it' variable that you get from your .each loop to assign a single value from this list to your new issue.
Try out this code, I did not directly test it but I made a few changes that I 'think' will fix the problems you mentioned:
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_10201")
def selectedSuppliers = issue.getCustomFieldValue(suppliers)
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("10101")
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)
}
If I misunderstood your issue or if you have any other questions, please let me know. :)
Jenna
Hi Jenna,
Thanks for your answer, it is working now! :)
Moreover, do you have any clue on how could I set the security level based on this custom field value?
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.