Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Use the value of a multi-select field as input for a summary of a subtask

Sander Spoelstra
Contributor
August 3, 2022

Hi,

I've got a script that creates a flexible number of subtasks based on the value of a multi-picker field. Specifically, the script creates a 'release subtask' per value of the multi select field. 

The possible values are:

  • TST
  • ACC
  • PRE
  • PRD

However, I want to include the value of the multi select in the summary of each subtask so I can differentiate between the subtasks. I've tried a lot of different ways but nothing seems to work. The arraylist is already defined so I should be able to use that as input for the summary, but can't get it to work.

The (working) script without the summary addition is.

Note that the script was found here in the Atlassian community and tweaked / updated to fit my situation.

// Imports
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.MutableIssue

// import for debug only
import org.apache.log4j.Logger
import org.apache.log4j.Level
log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)


Issue parentIssue = issue

//Get Value of Environment
CustomFieldManager cFM = ComponentAccessor.getCustomFieldManager()
String Environment = 'customfield_12090'
CustomField customfield_Env = customFieldManager.getCustomFieldObject(Environment)
Object customfieldIDValue_Env = (ArrayList) parentIssue.getCustomFieldValue(customfield_Env)

//Pre-define JQL Parser functions
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def activeUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//Pre-define Sub-Task Generation functions
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()



//This is where I don't want the full array, but only one of the values in the array per subtask
def summary = "Release subtask - " + customfieldIDValue_Env

//Get Values to copy from Parent
def dueDate = parentIssue.getDueDate()
def project = parentIssue.getProjectObject()
def description = parentIssue.getDescription()
def priority = parentIssue.getPriority()
def component = parentIssue.getComponents()

//Define Sub-Task Type
def issueTypeId = constantManager.getAllIssueTypeObjects().find{it.getName() == "Simplified - Release"}.id

//Iterate through and create subtasks
for (int i = 0; i < customfieldIDValue_Env.size(); i++){

//Create core values for subtasks
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setProjectObject(project)
newSubTask.setIssueTypeId(issueTypeId)
newSubTask.setParentObject(parentIssue)
newSubTask.setSummary(summary)
newSubTask.setDescription(description)
newSubTask.setDueDate(dueDate)
newSubTask.setComponent(component)
newSubTask.setPriority(priority)
newSubTask.setReporter(activeUser)

//Create Sub-Task
def newIssueParams = ["issue" : newSubTask] as Map
def createdSubTask = issueManager.createIssueObject(activeUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, createdSubTask, activeUser)
}

 

1 answer

1 accepted

1 vote
Answer accepted
Sander Spoelstra
Contributor
August 3, 2022

Found it! 

Defined the summary at the wrong stage of course :)

 

//Iterate through and create subtasks
for (int i = 0; i < customfieldIDValue_Env.size(); i++){
def summary = "Release subtask - " + customfieldIDValue_Env.get(i)

Suggest an answer

Log in or Sign up to answer