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"}
}
No matter what I tried, IssueService.update worked only from script console.
I added the below line and now it works
if(updateValidationResult.isValid()){
IssueService.IssueResult updateResult = issueService.update(sdUser, updateValidationResult)
issue.setOriginalEstimate(estimationLong) //added line
log.info("Issue " + issue.getKey() + " estimation updated!")
I just stumbled on the same problem (script updating remainingEstimate that was working from console and not as post-function) and that same line fixed it.
Never experienced something similar, and I would've never thought about that extra line... still wondering why it works just after that, though!
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindly put the post function last in the list of your post functions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexey,
That was my first approach (in fact I always put the script post functions last), though still the error persisted.
Any ideas?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.