Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hello,
I am new to Groovy and I am trying to write a script that will not allow a transition to the closed state of the workflow if all of these conditions are true:
I am not having much success. My script always passes and I can not see why. Here is the code I have:
// Give error message if (all 3 need to be true):
// 1) Issue type is NOT epic nor sub-task
// 2) Resolution is Done or Fixed on Dev
// 3) Release Comment is empty
import com.atlassian.jira.component.ComponentAccessor
// Message
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
// Custome fields: release comments
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def releaseComments = customFieldManager.getCustomFieldObjectByName("release comments")
// Valid type?
if (issue.getIssueType() != "Epic" && ! issue.getParentId()) {
// Resolution is Done or Fixed on Dev?
if (issue.getResolution() == "Done" || issue.getResolution() == "Fixed on Dev") {
// Release comments are blank
if (issue.getCustomFieldValue(releaseComments) == "") {
UserMessageUtil.error("Release Comments required when resolution is Done or Fixed on Dev.")
return false
}
}
}
return true
To be honest, I am not sure I am doing this correctly so any hints or tips for my code are welcome.
FYI: we have Jira 7.3.6 and ScriptRunner 5.4.1
Andrew
My guess is that your logic is broadly right, but your equivalence checks (==) are not.
For example, getIssueType() will return an issueType object, not a string, so your check for "is not epic" is always going to return true. Similarly for resolution
A little more formally (I'm happier in Java than groovy for this), I would try:
if ("Epic".equals(issue.getIssueType().getName()) && ! issue.getParentId()) {
// Resolution is Done or Fixed on Dev?
if ("Done".equals(issue.getResolution().getName()) || "Fixed on Dev".equals(issue.getResolution().getName())
The comments one might be ok as it is. I'm not sure of issue.getParentId, I think that's ok too, but might be wrong.
Hi, Nic,
Thanks for your reply. I tried your suggestions and I think I might be getting somewhere. I added these lines in as a debugging aid:
if (! "Epic".equals(issue.getIssueType().getName())) { log.error("Issue type is NOT Epic (good)") } else { log.error("Issue type is Epic (no release comments needed)")}
if (! issue.getParentId()) { log.error("Parent Id is null (good)") } else { log.error("Parent Id is not null (subtask)")}
if ("Done".equals(issue.getResolution().getName())) { log.error("Resolution is Done (good)") } else { log.error("Resolution is NOT Done (but is it Fixed on Dev?)")}
if ("Fixed on Dev".equals(issue.getResolution().getName())) { log.error("Resolution is Fixed on Dev (good)") } else { log.error("Resolution is NOT Fixed on Dev")}
if (issue.getCustomFieldValue(releaseComments) == "") { log.error("Release comments are empty") } else { log.error("Release Comments are NOT empty")}
However, it does not like this bit:
"Done".equals(issue.getResolution().getName())
as it gives the error:
java.lang.NullPointerException: Cannot invoke method getName() on null object at Script133.run(Script133.groovy:17)
Now, Resolution has a default value of Done on the Resolve Issue screen, which is displayed before the script is executed. So, for me (ex-mainframe programmer), issue.getResolution() should not be null. But what do I know?
Andrew
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.