I'm using the built-in custom listener script 'Create a sub-task' and I follow the guidance here.
I have set the trigger events to Issue Created and Issue Updated. And whenever the parent issue is either created or updated with a custom field value = xyz, it will create the subtasks. Works like charm.
But now, every time the parent issue is updated on any field, it will create more sub-tasks.
I cannot share a screenshot but my code looks like this
Under Conditions:
def cf = customFieldManager.getCustomFieldObjectsByName("Radio Button")
def cfValue = cf.getAt(0).getValue(issue)
if (issue.issueType.name == "Bug" &&
cfValue.toString().equals("XYZ") &&
issue.getSubtaskObjects().find {it.summary() != "Custom summary here"}){
return true
}
Target issue set to 'sub-task',
copy all fields,
under Additional issue actions:
issue.summary = 'Custom summary here'
I've also tried using 'Subtask Action' and set it to 'Done', but the script still auto creates more subtasks as "To Do".
What do I need to add if I want the built-in script to search via the summary, and if that subtask summary already exist, then it will not create?
Hi, @Diana Gorv
Try this condition
def cf = customFieldManager.getCustomFieldObjectsByName("Radio Button")
def cfValue = cf.getAt(0).getValue(issue)
if (issue.getSubtaskObjects().find { it.summary() != "Custom summary here" }) {
if (issue.issueType.name == "Bug" && cfValue.toString().equals("XYZ")) {
return true
}
} else {
return false
}
@Evgenii Thanks for the quick response
I tried your code, but it still keeps duplicating.
I added a log.warn to debug, and it looks like it's showing there are null subtasks in the parent issue
def cf = customFieldManager.getCustomFieldObjectsByName("Radio Button")
def cfValue = cf.getAt(0).getValue(issue)
if (issue.getSubtaskObjects().find { it.summary() != "Custom summary here" }) {
log.warn("Existing subtasks: " + issue.getSubtaskObjects().find {it.key} + " - " + issue.getSubtaskObjects().find {it.summary})
if (issue.issueType.name == "Bug" && cfValue.toString().equals("XYZ")) {
return true
}
} else {
return false
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Evgenii I made my fixes and still no luck.
I noticed that my logs is not showing the subtasks summary. It still points as null. I ran this script below on the Console to double check, and it.summary keeps return the issue keys and not the actual issue summary as a string
Ran this under Console to troubleshoot:
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
def im = ComponentAccessor.getIssueManager()
def issue = im.getIssueObject("ABC-123") //this is the parent issue key
Collection subtasks = issue.getSubtaskObjects()
subtasks.each {
it.summary
}
issue.getSubtaskObjects()*.summary.contains('Custom summary here')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To see summary in console, in .each loop you'll have to use log.warn
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
def im = ComponentAccessor.getIssueManager()
def issue = im.getIssueObject("ABC-123") //this is the parent issue key
Collection subtasks = issue.getSubtaskObjects()
subtasks.each {
log.warn it.summary
}
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.