Forums

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

ScriptRunner For Jira Cloud: Close specific issues when parent task is resolved

Anton Topchii
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!
November 19, 2021

Hi! I am trying to write a listener/post-function which close specific related issues when parent issues status changes to "Done"

At the moment I have the following code:

def issueKey = 'elpa-78'

//get all fields from parent task
def response = get("/rest/api/2/issue/" + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)

def issueSummary = response.body.fields.summary

//Determine the type of task, check if it fits the required types: "Первичное тестирование" or "Тестирование изменений"
if (response.body.fields.issuetype.name == "Первичное тестирование" || response.body.fields.issuetype.name == "Тестирование изменений") {
//If the task type is correct - check the status
if (response.body.fields.status.name == "Done") {
//If conditions above are satisfied, we parse all related tasks
response.body.fields.issuelinks.outwardIssue.each { it ->
//Determine the type of related task, check if it fits the required types: "Логика (Исходящие телеком)" or "Логика (Входящие/Other)"
if (it.fields.issuetype.name == "Логика (Исходящие телеком)" || it.fields.issuetype.name == "Логика (Входящие/Other)") {
//Check if the status of the current task matches the status "In testing"
if(it.fields.status.name == "In testing") {

transitionIssue(it.key)
PostComment(it.key, issueSummary, issueKey)

}
}
}
}
}

//changes related issues status
def transitionIssue(issueID){
post("/rest/api/2/issue/${issueID}/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: 101]])
.asObject(Map)
}

//leaves a comment
def PostComment(issueID, issueSummary, issueKey) {
post("/rest/api/2/issue/${issueID}/comment")
.header('Content-Type', 'application/json')
.body([
body: """
Родительская задача: [${issueSummary}|https://neuronet.atlassian.net/browse/${issueKey}] была закрыта.
Произведен перевод действующей задачи в статус "Done"
"""
])
.asObject(Map)
}

If i run it on Scriptrunner Script Console I get the result I want: all related to parent task issues changes their status to "Done" if their current status is "In Testing" and issue types matches required types.

But if i put this code into scriptrunner listeners or post-functions (where he is supposed to work), code above close only 1 issue from all related issues and leaves no comments.

Can anyone please help me understand what is the problem in this code?

When i use it on scriptrunner listeners or post-functions i change specific lines of code:
instead of:

def response = get("/rest/api/2/issue/" + issueKey) 

 i use:

def response = get("/rest/api/2/issue/$(issue.key}")

 

1 answer

1 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 19, 2021

Hi @Anton Topchii welcome on the community. I checked the code brieffly and I would expect described behaviour when PostComment method invocation fails on the first issue. Can you see some errors when the postfunction is executed (you can see it on the postfunction configuration screen)?

Anton Topchii
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!
November 19, 2021

@Martin Bayer _MoroSystems_ s_r_o__Thanks a lot! I found the problem - when i used the post-function i passed an empty value to the issueKey variable in

def PostComment(issueID, issueSummary, issueKey)
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 19, 2021

You are welcome, happy to help 😉

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events