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:
