I am trying to update the original estimate of an issue and I've come up with the script below.
Problem is that when ran from the console, script works and updates the issue correctly, but when ran as a post function it does not update the value.
Order of post function does not matter because If i try debugging,there are no changes in the originalEstimate field.
I'm sure I'm missing some kind of "update/save issue" , but can't seem to find out what specifically even after going through the docs.
Any help is appreciated.
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Level
log.setLevel(Level.INFO)
//Get the current Issue
Issue issue = issue
//sduser
def authContext = ComponentAccessor.getJiraAuthenticationContext()
authContext.setLoggedInUser(ComponentAccessor.getUserManager().getUserByKey('sdagent'))
def sdUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//get estimation values
def estimationDEV = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Estimation DEV'))
def estimationGDCf = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Estimation G&D'))
def estimationOPSCf = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Estimation OPS'))
//sum of estimation to string
def totalEstimation = (((estimationDEV!=null) ? estimationDEV : 0) + ((estimationGDCf!=null) ? estimationGDCf : 0) + ((estimationOPSCf!=null) ? estimationOPSCf : 0))
def estimationString = totalEstimation.toString() + "d"
//init issue service and input parameters for issue update
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
def existingEstimation = ((issue.getOriginalEstimate() != null) ? (issue.getOriginalEstimate()/8 /60 /60) : 0).toString() +"d"
issueInputParameters.setOriginalEstimate(estimationString)
issueInputParameters.setComment("Demand Original Estimate updated from "+ existingEstimation + " to " + estimationString + "!", 10301.longValue()) //10301 is ID of Project Role IT, send as long
IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate( sdUser, issue.getId(), issueInputParameters)
if(updateValidationResult.isValid()){
IssueService.IssueResult updateResult = issueService.update(sdUser, updateValidationResult)
log.info("Issue " + issue.getKey() + " estimation updated!")
//if i log.info(issue.getOriginalEstimate()) here, it still shows no changes
if(!updateResult.isValid()) {
updateResult.errorCollection.errorMessages.each {log.warn "Error Message: $it"}
updateResult.errorCollection.errors.each {log.warn "Error: $it"}
updateResult.errorCollection.reasons.each {log.warn "Reason: $it"}
}
}else{
updateValidationResult.errorCollection.errorMessages.each {log.warn "Error Message: $it"}
updateValidationResult.errorCollection.errors.each {log.warn "Error: $it"}
updateValidationResult.errorCollection.reasons.each {log.warn "Reason: $it"}
}