Forums

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

Sum of custom field values from subtasks in parent issue custom by listener

Kim Chen
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 10, 2024

Hello guys,

I wanted to use scriptrunner listener to  sum custom field values of all subtask for parent issue type .

my code is :

 

def currentIssue = issue

if (currentIssue.parentObject.issueTypeObject.name == 'Task') {
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def lastChangeItem = changeHistoryManager.getAllChangeItems(currentIssue).last()
if (lastChangeItem?.field == '10409') {
def totalWeakness = 0
Issues.search("project = '${currentIssue.projectObject.key}' AND parent ='${currentIssue.parentObject.key}' AND issuetype = 'Sub-task'").each { subtask ->
def weaknessValue = subtask.getCustomFieldValue('10409') as Double
if (weaknessValue) {
totalWeakness += weaknessValue
}
}
def parentIssue = currentIssue.parentObject
parentIssue.update {
setCustomFieldValue(10410, totalWeakness.toString())
}
}
}
now when I update the issue , code can run,10410 value will become  all Sub-task 10409 sum value,
but when I create a new Sub-task from task , the value of 10410 has not change, can someone helps me~
and this is my listener setting:截圖 2024-01-10 下午6.42.58.png

0 answers

Suggest an answer

Log in or Sign up to answer