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 http://docs.atlassian.com/software/jira/docs/api/latest/, I see this is how I obtain aggregate original estimate:

http://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/issue/fields/AggregateOriginalEstimateSystemField.html

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: https://confluence.atlassian.com/display/JIRA/API+Documentation or you can get in touch with an Atlassian Expert: http://www.atlassian.com/resources/experts/ that may be able to assist you. Unfortunetly, custom plugins are outside of the Atlassian Support Offerings (http://www.atlassian.com/resources/experts/) and we can not assist you with developing this.

2 answers

1 accepted

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.jira.security.JiraAuthenticationContextImpl

import com.atlassian.velocity.VelocityManager

import com.atlassian.jira.config.properties.ApplicationPropertiesImpl

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

import com.atlassian.jira.issue.search.SearchProviderFactoryImpl

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.security.ThreadLocalCachingPermissionManager

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(),

componentManager.getProjectFactory()))

IssueImplAggregateTimeTrackingCalculator iiattc = new IssueImplAggregateTimeTrackingCalculator

(jac,componentManager.getPermissionManager())

AggregateTimeTrackingBean bean = iiattc.getAggregates(issue)

AggregateOriginalEstimateSystemField aoesf = new AggregateOriginalEstimateSystemField

(componentManager.getVelocityManager(),componentManager.getApplicationProperties(),

jac,attcfi)

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

CustomFieldImpl lockedEstimate = componentManager.getCustomFieldManager().

getCustomFieldObject(10214)

// finally calculating the answer

Long summedEstimate = aoesf.getAggregateDuration(bean)

summedEstimate == null ? summedEstimate = 0 : summedEstimate

lockedEstimate

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

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

new DefaultIssueChangeHolder())

return true

0 vote

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

93 views 0 1
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