You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Similar to this question, but I'm running into an error where the auto creating subtask will only create the last option in the checkbox list, and not all options selected after an edit.
Example:
Checkbox field at the parent issue after 1 edit:
Expected Results, subtask's summary as:
Actual Results:
In the listener script, I set Event trigger to Issue Created and Issue Updated. Under Conditions I use:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def cf = customFieldManager.getCustomFieldObjectsByName("Checkbox")
def cfValue = cf.getAt(0).getValue(issue)
def subtaskSummaries = (cf as Collection<Option>)*.value
if(issue.issueType.name == "Parent" && cfValue != null){
if(!issue.getSubTaskObjects()*.summary.equals(subtaskSummaries)){
return true
}
}
def cf = customFieldManager.getCustomFieldObjectsByName("Checkbox").getAt(0)
def cfValue = sourceIssue.getCustomFieldValue(cf)
def subtaskSummaries = (cf as Collection<Option>)*.value
subtaskSummaries.each {
if(!sourceIssue.getSubTaskObjects()*.summary.contains(it)){
issue.summary = "Subtask: " + it
}
}
Here is a scripted listener I wrote that is very similar to what you want. It uses a checkbox field as the source for creating subtasks. The subtask summary is a bit over the top, but it's what they wanted :shrug:
package Listeners
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.event.issue.IssueEvent
final sourceFieldName = "Required Reviews"
IssueEvent issueEvent = event as IssueEvent
Issue parentIssue = issueEvent.issue
if (!issueEvent?.getEventTypeId()?.equals(EventType.ISSUE_CREATED_ID) &&
!issueEvent?.getChangeLog()?.getRelated("ChildChangeItem")?.find { it.field == sourceFieldName })
return
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
// Logging configuration
import org.apache.log4j.Logger
import org.apache.log4j.Level
final Logger log = Logger.getLogger("com.joby.melville")
log.setLevel(Level.INFO)
log.setAdditivity(false)
// Re-indexing
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
def reIndexIssue(issue) {
//Re-index the issue after update
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing)
}
def optionSuffix = " Review: " // tacked on to cf option to create Summary Prefix
def subtaskIssueType = "Review Subtask"
def selectFieldsToClone = [ 'Installation Stage', 'Document Category']
def constantManager = ComponentAccessor.getConstantsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
ApplicationUser user = issueEvent.getUser()
def cf = customFieldManager.getCustomFieldObjects(issue).findByName(sourceFieldName)
if (cf == null)
return
def optionList = (issue.getCustomFieldValue(cf) as Collection<Option>)*.value
def modified = false
optionList.each {
subtaskSummary = it + optionSuffix
log.info("${sourceFieldName}: ${subtaskSummary}")
if (!issue.getSubTaskObjects()*.summary.find { it.startsWith(subtaskSummary) }) {
// no existing subtask has a matching prefix
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary(subtaskSummary + parentIssue.summary)
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setReporter(user)
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == subtaskIssueType}.id)
def cff
selectFieldsToClone.each {
cff = customFieldManager.getCustomFieldObjects(parentIssue).findByName(it)
if (cff == null)
log.error("Custom Field not found: ${it}")
else
newSubTask.setCustomFieldValue(cff, parentIssue.getCustomFieldValue(cff))
}
//newSubTask.setAssigneeId(parentIssue.assigneeId)
def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
reIndexIssue(newSubTask)
modified = true
log.info "Created ${newSubTask.summary}"
}
}
if (modified)
reIndexIssue(parentIssue)
@Chris Melville Thank you so much! this works!
I only made a few changes to the re-indexing portion. For some reason I get a "cannot find matching method" on IssueIndexingService, even though I've imported the class. I even trying defining it as variable.
So instead of using 'reIndexIssue' i just tell it to reindex at the very end within the curly brackets:
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
issueIndexingServce.reIndex(issueManager.getIssueObject(newSubtask.id))
ImportUtils.setIndexIssues(wasIndexing)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can't use the "create sub task" built-in script to create multiple subtasks.
You'll have to use a "Custom scripted listener" and build the sub-tasks yourself.
You'll have to loop through all the selected options in the checkbox field and create sub-tasks in that loop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehan that makes more sense. I was wondering why it was only creating only 1 subtask at a time, even when I add logs to track.
Thanks for the response back.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.