With Scriptrunner listeners, I'm using a custom script that triggers on Issue Created. When a new issue has a certain radio button value selected, the script will auto create another new issue, cloning the original issue, but it changes a single select list to a different value (field name Team). But the new cloned issue will not properly re-assign. Everything else clones properly.
import com.atlassian.jira.componentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.ApplicationUser
//define objects
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def optionsManager = ComponentAccessor.getOptionsManager()
def issue = event.issue
def radioField = customFieldManager.getCustomFieldObjectsByName("Radio").getAt(0)
def radioFieldValue = radioField.getValue(issue)
def storyType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="Story"}
def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//only on features and if radioField is Yes
if(issue,issueType.name == "Feature"){
log.warn("Checking if radioField is needed on Feature: " + issue.key)
if(radioField.toString() == "Yes") {
log.warn("Creating new story since radioField is: " + radioFieldvalue)
//clone issue to a story
def toClone = issueFactory.cloneIssueWithAllFields(issue)
toClone.setIssueTypeObject(storyType)
//create new issue
def cloned = issueManager.createIssueObject(currentUserObj, toClone) as MutableIssue
def newIssue = issueManager.getIssueObject(cloned.key)
log.warn ("new issue: " + newIssue)
//clone epic link
def epic = customFieldManager.getCustomFieldObjectsByName("Epic Link").getAt(0)
def epicConfig = epic.getRelevantConfig(issue)
def epicOptions = optionsManager.getOptions(epicConfig).getOptionForValue(epic.toString(),null)
toClone.setCustomFieldValue(epic, epicOptions)
//multiple of other custom fields also get cloned with no problem
//re-assigned cloned issue to a different team
def team = customFieldManager.getCustomFieldObjectsByName("Team").getAt(0)
def teamConfig = team.getRelevantConfig(cloned)
def teamValue = cloned.getCustomFieldValue(team)
def teamOption = optionsManager.getOptions(teamConfig).getOptionForValue(teamValue.toString(),null)
def assignTeam = teamOption.toString().equals("Team A")
cloned.setCustomFieldValue(team, assignTeam)
log.warn("Assigned to Team: " + teamValue)
}
}
Because the newly cloned issue has null value for Team, how do I set the cloned issue to a specific value?