Forums

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

I need a help with script runner code execution, when all linked issues are closed, close epic

Mahi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 28, 2023

I'm a newbie to script runner cloud version, while executing this code it is not working as expected.

I request Script runner team to look into this issue

 

def issueKey = "HDWSEC-8"

// Specify the name of the version to extract from the issue
def closedStatus = 'Done'

// Specify the transition to execute on the issue
// NOTE - The transition ID must represent a valid transition for the workflow that the issue uses.

def transitionID = '3'

// Specify a boolean to flag if all issue links are resolved
boolean allIssueLinksResolved;

// Get the issue object
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)

// Find the linked issues
def linkedIssues = result.body.fields.issuelinks

// if all issue links have the Done status set the flag to true
if(linkedIssues.findAll{closedStatus.contains(it.outwardIssue.fields.status.name)}){
allIssueLinksResolved = true
}

// If any of the linked issues do not have the done status set the flag to false
if (linkedIssues.findAll{!closedStatus.contains(it.outwardIssue.fields.status.name)}){
allIssueLinksResolved = false
}

// If all issue links are resolved transition the issue
if(allIssueLinksResolved == true){

// The rest call to transition the issue
def transitionIssue = post("/rest/api/2/issue/${issueKey}/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: transitionID]])
.asObject(Map)

return "All issue links are to closed issues and the issue has been transitioned."
// If the issue contains unresolved linked issues return a message and do not transition the issue
}else if (allIssueLinksResolved == false){
return "The issue contain issue links which are not closed"
}

1 answer

0 votes
Trudy Claspill
Community Champion
December 28, 2023

Hello @Mahi 

Welcome to the Atlassian community.

If you want help directly from Adaptavist ScriptRunner support, you need to contact them directly. Their contact information can be found in their Atlassian Marketplace listing on the Support tab.

https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=cloud&tab=support

 

This location, where you have posted your question, is a user community for the Jira product. While we may be able to help you debug your script, you will need to provide us with more information.

 

In your first sentence you said that the code is running "as expected". Can you explain what help you need? Do you mean it is not running as expected? If so, what are you trying to accomplish with the code?

 

You seem to be trying to get information about issues Linked to the Epic. That would be different than the issues that are Child Issues of the Epic. Are you sure you want to look at Linked issues, or do you actually want to look at Child Issues?

Mahi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 29, 2024

Hey Trudy,

I appreciate your response and a small correction (it's not working as expected)

 

STR:

There are few linked issues related to the epic.

When we transition all linked issues to done status, the epic status must move to done status.

This is the logic that needs to be executed, But the above shared code is not performing action.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events