Is it possible to automatically change the Epic Status based on it's issues with ScriptRunner?

Alexandra Sousa DECSKILL December 11, 2019

Hello Community,

 

I need to create an automation that changes the epic status based on the stories/tasks inside the epic.

For instance: automatic transition of an Epic to 'In Progress' when the first Story enters 'In Progress.'

Anyone has the code to help me with this situation using ScriptRunner, please?

Thanks in advance!

4 answers

2 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 12, 2019

Hi Alexandra,

I can confirm that the code samples provided above will not work with ScriptRunner for Jira Clouddue to the fact the code you have provided is for ScriptRunner for Jira Server and this will not work as Atlassian only provide a rest API in Jira Cloud and do not provide a Java API in the cloud-like they do in Jira Server.

You can see more detailed information on the differences between the cloud and server versions inside of our documentation page located here.

We would recommend reviewing the documentation for ScriptRunner for Jira Cloud which is located here along with the Jira Cloud Rest API Documentation in order to see how the REST API's work in Jira cloud.

I can confirm that it is possible to achieve your requirement using ScriptRunner for Jira Cloud and can confirm that to achieve this that you would need to create a Script Listener which is configured on the Issue Updated event.

The script Listener code would need to return all of the linked issues linked to the epic issue and to check if the first story issue was in the required status and if it was to transition the epic issue.

I can confirm that the example script located here shows how to get stories attached to an epic and you will be able to use this script as a reference guide to see how to get the stories in order to check if the first story is in the required status.

I can also confirm that we have an example script located here which shows how to transition an issue when all linked issues are in the closed status and that this script may be a useful reference guide to see how to transition an issue.

You will be able to take these scripts and use this as a reference guide to help create the script that you require which transitions the epic issue when the first story is in the required status.

I hope this helps.

Regards,

Kristian

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 12, 2019

Very useful resources, I did miss that part :( 

Thanks @Kristian Walker _Adaptavist_ 

Alexandra Sousa DECSKILL December 13, 2019

Thank you so much @Kristian Walker -Adaptavist- !

I will try it and let you know :) 

0 votes
Rajesh Ramankutty February 6, 2022

@Alexandra Sousa DECSKILL @Leo @Kristian Walker _Adaptavist_ @Leonard Chew 

 

I need to move epic from In Development to In QC

When all the story is in Done Status can u tell me how to do it .

0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 11, 2019

Hi @Alexandra Sousa DECSKILL,

I've tried this code in Server platform but not on Cloud, it may need some minor changes

I placed this script in post-function of story workflow in "in progress" transition

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 31 // change this to the step that you want the issues to be transitioned to

def transitionValidationResult
def transitionResult


def epicLink = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Epic Link")
def epic = issue.getCustomFieldValue(epicLink) as String
if(epic){
def issueE = issueManager.getIssueObject(epic);
if(issueE.getStatus().name != "In Progress" )
{
transitionValidationResult = issueService.validateTransition(currentUser, issueE.id, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}else{
log.debug("The transitionValidation is not valid")
}

}
}

 Note: you must replace the actionID which is transition ID, also make sure Epic has transition to target status from current status, and check for validation/condition in workflow

 

BR,

Leo

Alexandra Sousa DECSKILL December 13, 2019

Thank you so much for your help Leo! 

0 votes
Leonard Chew
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 Leaders.
December 11, 2019
Alexandra Sousa DECSKILL December 11, 2019

Hello Leonard,

Thanks for your reply! 

I already tried that option but it did not worked.

Thanks anyway! 

Suggest an answer

Log in or Sign up to answer