Need Help Crafting Javascript

My goal:

Copy the value of aggregate original estimate to a custom field at a specific place in the workflow. My intention is to use groovyrunner plugin's "Script Post Function" ability to obtain and copy the value into my custom field called Locked Estimate (cf[10214]). Looking at the API at, I see this is how I obtain aggregate original estimate:

My question:

I've never written javascript. Will any kind souls feel pity on me to help me craft such a script?

Final Thoughts:

I wish I didn't have to restort to JS to solve this problem, but I found out from Atlassian that getting the data from aggregate original estimate was more involved than a copy from one cell to another via a post function.

In Atlassian's words:

I am sorry but the Original Estimate field does not simply store a numeric value and thus can not be copied out. I would recommend that you just ask your users to enter it twice. If you would like a cleaner solution than you may need a custom plugin to accomplish this. You can look into our API at: or you can get in touch with an Atlassian Expert: that may be able to assist you. Unfortunetly, custom plugins are outside of the Atlassian Support Offerings ( and we can not assist you with developing this.

2 answers

1 accepted

This widget could not be displayed.

i took a few hours to dust off the programming skills. i'm sorely out of practice, and this undoubtedly could be optimized. nonetheless, it does the trick.

import com.atlassian.jira.ComponentManager


import com.atlassian.velocity.VelocityManager


import com.atlassian.jira.issue.fields.AggregateOriginalEstimateSystemField


import com.atlassian.jira.project.DefaultProjectFactory

import com.atlassian.jira.permission.DefaultPermissionContextFactory

import com.atlassian.jira.permission.PermissionTypeManager

import com.atlassian.jira.permission.WorkflowPermissionFactory


import com.atlassian.jira.issue.util.AggregateTimeTrackingCalculatorFactoryImpl

import com.atlassian.jira.issue.util.AggregateTimeTrackingBean

import com.atlassian.jira.issue.util.IssueImplAggregateTimeTrackingCalculator

import com.atlassian.jira.issue.fields.CustomFieldImpl

import com.atlassian.jira.issue.managers.DefaultCustomFieldManager

import com.atlassian.jira.issue.fields.CustomFieldImpl

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.fields.layout.field.DefaultFieldLayoutManager

import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem

import com.atlassian.jira.issue.ModifiedValue

// constructing objects for getting AOE value

ComponentManager componentManager = ComponentManager.getInstance()

JiraAuthenticationContextImpl jac = componentManager.getJiraAuthenticationContext()

AggregateTimeTrackingCalculatorFactoryImpl attcfi =

new AggregateTimeTrackingCalculatorFactoryImpl

(jac,new SearchProviderFactoryImpl(),new ThreadLocalCachingPermissionManager

(new WorkflowPermissionFactory(),componentManager.getPermissionContextFactory(),


IssueImplAggregateTimeTrackingCalculator iiattc = new IssueImplAggregateTimeTrackingCalculator


AggregateTimeTrackingBean bean = iiattc.getAggregates(issue)

AggregateOriginalEstimateSystemField aoesf = new AggregateOriginalEstimateSystemField



// constructing objects for getting/setting custom field Locked Estimate

CustomFieldImpl lockedEstimate = componentManager.getCustomFieldManager().


// finally calculating the answer

Long summedEstimate = aoesf.getAggregateDuration(bean)

summedEstimate == null ? summedEstimate = 0 : summedEstimate


.updateValue (componentManager.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(lockedEstimate),

issue,new ModifiedValue(lockedEstimate.getValue(issue),summedEstimate as Double),

new DefaultIssueChangeHolder())

return true

This widget could not be displayed.

You need the com.atlassian.jira.issue.util.AggregateTimeTrackingBean IIRC... I have done this before but can't find sample code. Probably best to look at the jira source.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

199 views 1 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you