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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,304 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot