Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can estimate of a subtask be automatically subtracted from the parent task`s estimate

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?

2 answers

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.

Like Filip Škledar likes this
0 votes

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)

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you