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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.