set the original estimate and remaining estimate based on 2 fields

Omprakash Thamsetty
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.
March 20, 2019

Jira 7.7.2 and Script runner plugin 5.5.0

Here is my requirement. I have DEV Estimate and BA Estimate custom fields. We needs to take total of these 2 fields and then update in original estimate.

I have written code in script listener and its updating original estimate and remaining estimate if DEV estimate and BA estimate change . So far good

But Its not working when user log the hour (log work) and then change DEV  or BA estimation. It should add both DEV and BA estimation values and then update in original estimation. whereas remaining hours getting update fine.

 

Here is my code. Please let me know whats wrong in my code.

 

package com.custom
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters
import org.apache.log4j.Category;
log.setLevel(org.apache.log4j.Level.DEBUG)


MutableIssue issue = event.issue as MutableIssue

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def orgEstDEV = customFieldManager.getCustomFieldObjectByName("Original Estimate DEV")
def orgEstDEV_Val = issue.getCustomFieldValue(orgEstDEV)
def orgEstBA = customFieldManager.getCustomFieldObjectByName("Original Estimate BA")
def orgEstBA_Val = issue.getCustomFieldValue(orgEstBA)

//log.debug "BA val = ${orgEstBA_Val}"

//long totalDEVBAEst = (((orgEstDEV_Val!=null) ? orgEstDEV_Val : 0) + ((orgEstBA_Val!=null) ? orgEstBA_Val : 0))

long totalDEVBAEst = orgEstDEV_Val + orgEstBA_Val


long origEstvalue = totalDEVBAEst * 3600
log.debug "Original est = ${origEstvalue}"


def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

//Remaining hours
def TTSpent = issue.getTimeSpent();
if(TTSpent < 0 || TTSpent == "null" || TTSpent == ""){ //Keep the Remaining Estimate from going into a negative number
TTSpent = 0;
}

long REst = origEstvalue - TTSpent;
issue.setEstimate(REst);

issue.setOriginalEstimate(origEstvalue)
def IssueManager issueManager = ComponentAccessor.issueManager
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH ,false)

1 answer

0 votes
Cristina Gatt August 26, 2019

Hi, 

We are having the same problem. JIRA Version: 7.9.2, Script Runner Version: 5.5.3

When there is no log work on the issue, the code below works fine, but this is not working when there is time logged on the issue.

issue.setOriginalEstimate(updatedEstimate as Long)
ComponentAccessor.getIssueManager().updateIssue(users, issue, EventDispatchOption.DO_NOT_DISPATCH,false);

 The code that updates even if work is logged on the issue, is when we use 'issue.store()' instead of 'ComponentAccessor.getIssueManager.updatedIssue(args) but this is deprecated. 

The code with the deprecated function is this:


issue.setOriginalEstimate(updatedEstimate as Long)
issue.store()

 

I also tried using IssueInputParameters, but this does not work either. I checked the Timetracking settings and  Legacy Mode is also disabled but still not working :(  

Any hints please on how this can be solved without using the deprecated function?

luka montin February 8, 2021

Hi @Omprakash Thamsetty  and @Cristina Gatt  did you ever get this to work ? 

Like Tobias Harneit likes this

Suggest an answer

Log in or Sign up to answer