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

0 votes
Accepted answer

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

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
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(),
IssueImplAggregateTimeTrackingCalculator iiattc = new IssueImplAggregateTimeTrackingCalculator
AggregateTimeTrackingBean bean = iiattc.getAggregates(issue)
AggregateOriginalEstimateSystemField aoesf = new AggregateOriginalEstimateSystemField
	(new DefaultVelocityTemplatingEngine(componentManager.getVelocityManager(),componentManager.getApplicationProperties()),componentManager.getApplicationProperties(),

/* AggregateOriginalEstimateSystemField aoesf = new AggregateOriginalEstimateSystemField

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,272 views 5 10
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