Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help Crafting Javascript

Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2012

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

1 vote
Answer accepted
Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 18, 2012

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 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 17, 2012

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
TAGS
AUG Leaders

Atlassian Community Events