I have a script that I've added to the Close transition as a validator.
Here's the script:
package Workflows.Validatorsimport com.onresolve.scriptrunner.runner.util.UserMessageUtilimport com.atlassian.jira.issue.Issueimport org.apache.log4j.Loggerimport org.apache.log4j.Levelimport Log****.*import Log****.Helpers.*Logger jiraLog = Logger.getLogger(this as String)jiraLog.setLevel(Log****Locale.logLevel)// Get the current issueIssue parentIssue = issuejiraLog.debug('Source Issue: ' + parentIssue.getKey())if (parentIssue.getSubTaskObjects().size() > 0) { def subTasks = parentIssue.getSubTaskObjects() jiraLog.debug('Associated sub-tasks: ' + subTasks) def allSubTasksDone = subTasks.every { it.status.name in ['Closed'] } jiraLog.debug(allSubTasksDone) if (!allSubTasksDone) { jiraLog.debug('Got to the part where all sub-tasks are not closed.') UserMessageUtil.info('Cannot close issue ' + parentIssue + ' as it has open sub-tasks') return false }else { jiraLog.debug('All sub-tasks are closed.') return true }}if (parentIssue.getSubTaskObjects().size() == 0) { jiraLog.debug('No sub-tasks associated with issue: ' + parentIssue) return true}
Hi @Jeramy ,
If you are using Custom script validator, then you need to throw an InvalidInputException instead of returning false.
So, just change
return false
tothrow new InvalidInputException("...")
throw new InvalidInputException("...")
@Salih Tuç - Perfect! That worked great. Thank you so much!
It looks like you're new here. Sign in or register to get started.