Cannot Copy Original Estimate Summation to Another Field

My intent:

I want to preserve the original estimate of a feature at a point in time in the workflow. I planned to do so by copying the summation of the original estimate to a custom field during the appropriate transition. I provided several screen shots of much of what I describe below.

Steps to reproduce:

1. Create a custom field called Locked Estimate of type Number.*

2. Create a post function during the appropriate transition that copies summation of original estimate to locked estimate.

3. Publish this new workflow feature.

4. Create a feature with 0 hour estimate and a sub-task with 2 hour estimate.

5. Advance this feature through the post-function.

* to ensure it wasn't some kind of field type conflict, i also tried copying the value from summation of original estimate to Time Spent on the post function. I got the same result as described below.

What I expected:

I expected the value would be preserved in Locked Estimate.

What actually happened:

I received an error. You'll see it as a screenshot.

1 answer

1 accepted

The code isn't pretty, but it answers the question:

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
import com.atlassian.jira.template.velocity.DefaultVelocityTemplatingEngine

// 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
	(new DefaultVelocityTemplatingEngine(componentManager.getVelocityManager(),componentManager.getApplicationProperties()),componentManager.getApplicationProperties(),
        jac,attcfi)

/* AggregateOriginalEstimateSystemField aoesf = new AggregateOriginalEstimateSystemField
	(componentManager.getVelocityManager(),componentManager.getApplicationProperties(),
        jac,attcfi)
*/

CustomFieldImpl lockedEstimate = componentManager.getCustomFieldManager().
	getCustomFieldObject(10305)

// 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

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
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

131 views 5 9
Read article

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