It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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!

3 answers

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 Dec 12, 2019

Very useful resources, I did miss that part :( 

Thanks @Kristian Walker _Adaptavist_ 

Thank you so much @Kristian Walker -Adaptavist- !

I will try it and let you know :) 

Hello Leonard,

Thanks for your reply! 

I already tried that option but it did not worked.

Thanks anyway! 

0 votes
Leo Community Leader Dec 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

Thank you so much for your help Leo! 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you