So i have a script that will create subtasks from values populated in a multiselect custom field, but it uses all the values in the custom field and not just the highlighted ones. Is there a way i can edit this script to use only the select values of the custom field??
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
// Does not run if the ticket is a subtask
if ( issue.getIssueType().isSubTask() ) return 0
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def subTaskTypeId = constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-Task" }.id
List<String> summariesList = []
// Get the values from the custom field 'Carrier' - Should probably change this to DB value of Carrier..
def buildFromField = customFieldManager.getCustomFieldObjects(issue)find {it.name == "Carrier"}
def optionsFieldConfig = buildFromField.getRelevantConfig(issue)
def optionsFound = optionsManager.getOptions (optionsFieldConfig)
// Compile the summary name of the subtask to be created
optionsFound.each { optionName ->
summariesList.add( optionName.getValue() + ": " + issue.getSummary())
}
// Create the subtasks
summariesList?.each { subTaskSummary ->
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary(subTaskSummary)
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(subTaskTypeId)
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, currentUser)
}