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)