Let say we have a situation where we open task and put rough Estimate on task. Like 20 hours or so. After a while we open a subtask, that we estimate takes 3 hours to finish. Is there a script that substract Parent estimate automatically so estimate on parent is now 17 hours. After some time we open another task and estimate is 6 hours, so Parent task is now 11.
Is there any script or some other solution that doesn't include automation rules?
As an example, I use a Listener on Issue Updated event.
1. Navigate ScriptRunner > Script Listeners > Make appropriate configurations.
2. Choose to listen on "Issue Updated" event.
3. Under "Code to run", use following script:
def hasEstimateChanged = changelog.items.any {(it as Map).field == "timeoriginalestimate"}
def issueFields = get('/rest/api/2/issue/' + issue.key)
.header('Content-Type', 'application/json')
.asObject(Map)
.body
.fields
def parentIssueKey = issueFields.parent?.key
if (hasEstimateChanged && parentIssueKey) {
def childOriginalEstimate = issueFields.timetracking.originalEstimateSeconds as Number
def parentOriginalEstimate = get('/rest/api/2/issue/' + parentIssueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
.body
.fields
.timetracking
.originalEstimateSeconds as Number
def result = put("/rest/api/2/issue/$parentIssueKey")
.header('Content-Type', 'application/json')
.body([
fields:[
timetracking: [
originalEstimate: parentOriginalEstimate/60 - childOriginalEstimate/60
]
]
])
.asString()
}
You should aware the following few points:
1. I assume, with the new issue view, you can't set estimate when creating subtask. So, the listener is just listening on Issue Updated event.
2. The listener will always subtract parent's estimate whenever estimate in subtask changes. Probably, you want to modify the script to account for this situation by adding the old value back to parent's estimate and subtracting the new value.
3. Anyone can still manually change parent's estimate.
I hope this helps!
I have modified the script to account for the situation where estimate in subtask changes:
def hasEstimateChanged = changelog.items.any {(it as Map).field == "timeoriginalestimate"}
def issueFields = get('/rest/api/2/issue/' + issue.key)
.header('Content-Type', 'application/json')
.asObject(Map)
.body
.fields
def parentIssueKey = issueFields.parent?.key
if (hasEstimateChanged && parentIssueKey) {
def childOldEstimate = changelog.items.find({(it as Map).field == "timeoriginalestimate"}).from as Number ?: 0
def childNewEstimate = issueFields.timetracking.originalEstimateSeconds as Number
def parentOldEstimate = get('/rest/api/2/issue/' + parentIssueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
.body
.fields
.timetracking
.originalEstimateSeconds as Number
def result = put("/rest/api/2/issue/$parentIssueKey")
.header('Content-Type', 'application/json')
.body([
fields:[
timetracking: [
originalEstimate: parentOldEstimate/60 + childOldEstimate/60 - childNewEstimate/60
]
]
])
.asString()
}
Another rare situation you should aware is where the subtask is converted or moved. You probably need another listener for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This script is not quite what you need, but it does show you broadly how you might do this - https://library.adaptavist.com/entity/automate-epic-custom-field-sum
(Frankly, I prefer your approach - adding sub-task estimates up on to a parent issue is almost always a bad thing to do, people tend to fail to think through why they're doing it and then not understand when everything looks weird and wrong. Subtracting from a story's estimate is far more sensible)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.