I would like to prevent creation "issue B" of "Project B" by clicking button "Create linked issue" from "issue A", if "issue A" has status "Closed".
And to do this, I used two approaches:
1. The first way. I created "Validator" of "Create" transition in "Workflow B" of "issue B" and wrote the following code:
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
log.info('1. Test')
def isEpicIssueClosed = false;
def sourceIssue = issue.getParentObject()
log.info('Source issue is ' + sourceIssue)
log.info('2. isEpicIssueClosed BEFORE: ' + isEpicIssueClosed)
log.info('3. The creacted issue is: ' + issue + '. Its status is '
+ issue.getStatus().name)
if(issue.getStatus().name == 'Closed') {
isEpicIssueClosed = true;
}
log.info('4. isEpicIssueClosed AFTER: ' + isEpicIssueClosed)
isEpicIssueClosed == false
But I see the following error:
2018-08-02 18:11:06,513 INFO [acme.CreateSubtask]: 1. Test
2018-08-02 18:11:06,513 INFO [acme.CreateSubtask]: Source issue is null
2018-08-02 18:11:06,515 INFO [acme.CreateSubtask]: 2. isEpicIssueClosed BEFORE: false
2018-08-02 18:11:06,515 INFO [acme.CreateSubtask]: 3. The creacted issue is: issue B
2018-08-02 18:11:06,517 ERROR [utils.ConditionUtils]: *************************************************************************************
2018-08-02 18:11:06,517 ERROR [utils.ConditionUtils]: Condition failed on issue: null, built-in script:com.onresolve.scriptrunner.canned.jira.workflow.validators.SimpleScriptedValidator
java.lang.NullPointerException: Cannot invoke method getName() on null object
at Script2802.run(Script2802.groovy:28)
Consequently, it does not work like I wanted.
2. The second way. I used ScriptRunner approach "Hide system or plugin UI element" and wrote the following code:
!(jiraHelper.project?.key == "LO"
&& issue?.issueType?.name == 'Epic'
&& issue?.getStatus()?.getName() == 'Closed')
But this approach hides button "Create linked issue" and I cannot create any issue of other projects such as "Project C", "Project D", "Project E".
So guys, how is it possible to prevent creation "issue B" of "Project B" by clicking button "Create linked issue" from "issue A", if "issue A" has status "Closed"?