Issue Service not updating value when used in transition

Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 1, 2018

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"}
}

 

2 answers

1 accepted

1 vote
Answer accepted
Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 2, 2018

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!")
Marco Baldelli September 10, 2018

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!

0 votes
Alexey Matveev
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 1, 2018

Kindly put the post function last in the list of your post functions

Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 2, 2018

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

Suggest an answer

Log in or Sign up to answer