The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

prevent closing an Epic until all linked issues are closed

Uday Kiran Raparthy
August 6, 2020

What would the coding in Scriptrunner be if I don't have the JMWE add-on available? Could you help me with this one?

Requirement: "Close epic only possible when all stories and bugs related are closed". using Status category = Done

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Tamas Baglyas
Contributor
August 6, 2020

Hi @Uday Kiran Raparthy ,

You can add the following script as a Workflow Condition:
Conditions -> Add condition -> Script Condition [ScriptRunner] -> Simple scripted condition
And if you want to be sure to no one can trick, add the same script as a Workflow Validation:
Validators -> Add validator -> Script Validator [ScriptRunner] -> Simple scripted validator

/**
* Atlassian Community answer
* <a href="https://community.atlassian.com/t5/Jira-questions/prevent-closing-an-Epic-until-all-linked-issues-are-closed/qaq-p/1450359" target="_blank">prevent closing an Epic until all linked issues are closed</a>
* @author Tamás Baglyas - https://github.com/tbaglyas
* @version 1.0
* @since 2020-08-06
*/
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.link.IssueLinkManager;

//If you want to test in Script Console
//MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("STUDIO-42");

//Current issue is Epic or not
boolean allClosed = (!issue.getIssueTypeId().equals("6")) ? false : true; //Epic

if (allClosed) {
//If you want to test in Script Console
//IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();

//Get all Epic Linked issues; outwards and inwards
List<String> issueStatuses = issueLinkManager.getOutwardLinks(issue.getId()).findAll() {
it.issueLinkType.getId() == 10200L //Epic Link
}*.destinationObject*.getStatusId()?:[];
issueStatuses.addAll(issueLinkManager.getInwardLinks(issue.getId()).findAll() {
it.issueLinkType.getId() == 10200L //Epic Link
}*.sourceObject*.getStatusId());

//All Issues in Epic number equals Closed Issues in Epic
allClosed = (issueStatuses.size() == issueStatuses.findAll() { it.equals("6") }.size()) ? true : false; //Closed
}

allClosed

 

Cheers,

Tamás

Kristian Walker _Adaptavist_
Community Champion
August 6, 2020

Hi Tamas,

Please note that this code provided is for Jira Server and will not work in Jira Cloud which this ticket is marked as due to the fact Atlassian only provides a Rest API in Jira Cloud and does not provide  a Java api in Jira cloud like they do in Jira Server.

You can see further details between the cloud and server versions of ScriptRunner inside of the documentation page located here.

Regards,

Kristian

Tamas Baglyas
Contributor
August 6, 2020

Hi Kristian,

You're right. I skip the part that the question belongs to a Jira Cloud. Thank you for pointing me. In this case, my solution not really work in this form.

Cheers,
Tamás

0 votes
Kristian Walker _Adaptavist_
Community Champion
August 6, 2020

Hi Uday,

I can confirm that ScriptRunner for Jira Cloud provides the workflow conditions and workflow validators features that could be used to achieve this requirement and you can see further details of how these work here and here.

I can confirm we also have a sample condition located here which you will be able to take and to modify to help achieve your requirement.

I hope this information helps.

Regards,

Kristian

0 votes
Jack Brickey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
August 6, 2020

Hi Uday, under Related Content in the right-hand sidebar I found this post How-to-Prevent-Close-of-Epic-Until-All-of-its-Issues-are-Closed Which offers a Scriptrunner code example. You might give that a try.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events