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)
}
This line is the problem:
def optionsFound = optionsManager.getOptions (optionsFieldConfig)
It's going off to the field definition to get the list of possible options. You really need to be reading the data from the issue, not the custom field definition.
That means something like
def customFieldValue = issue.getCustomFieldValue(customField)
For a multi-select list, that will return an array of values you can iterate over
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
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField;
// Does not run if the ticket is a subtask
if ( issue.getIssueType().isSubTask() ) return 0
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def subTaskTypeId = constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-Task" }.id
List<String> summariesList = []
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def carrier = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Carrier")
def carrierValue = issues.getCustomFieldValue(carrier)
// 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)
}
Totally stuck.. keep getting this error..
groovy.lang.MissingPropertyException: No such property: issues for class: script1592223512190699815626
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65) org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51) org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309) script1592223512190699815626.run(script1592223512190699815626.groovy:25)
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.