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:
- the issue type is not Epic and it is not a sub-task
- the resolution is Done or Fixed on Dev
- the Release Comments are empty
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