ScriptRunner post function issueService.transition didn't set the status

When transitioning an issue in the post function with issueService.transition, the destination status (let's call it status2) is not set. 

  • On UI, the status stays at the source status (let's call it status1)
  • On UI, the History tab displays that the status was changed from status1 to status2
  • On UI, there are only 2 available transitions, which match neither status1 (it has 4 outgoing transitions, including the displayed two) nor status2 (it has 4 outgoing transitions, including the displayed two). 
  • From DB, the jiraissue table shows the status is status1
  • From DB, the changeGroup/changeItem table agrees with the UI History info
  • I output a log line after issueService.transition() and it got printed. The time elapse of this post function is roughly 110ms.
  • I catch Throwable around  issueService.transition() but nothing is caught
  • I waited for many minutes and the status is not updated. 
  • I indexed it and nothing has been changed. 

BTW, the post function is the last function on the post function list. 

I am using JIRA 7.2.6 software and ScriptRunner 4.3.1. 

Did anyone see any problem similar? Any suggestions will be highly appreciated. 

5 answers

Your code seems to be valid. There are two strange places: {} after try block instead { and line 

 issueInputParameters.setSkipScreenCheck(true)

I also refactored your code a little

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.user.ApplicationUser

IssueService issueService = ComponentAccessor.getIssueService()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)

log.info("Found workflow " + workflow.getDisplayName())
List<ActionDescriptor> oActions = workflow.getLinkedStep(issue.getStatus()).getActions();
log.info("Found " + oActions.size() + " actions for " + workflow.getDisplayName())
try{
for (ActionDescriptor oAction : oActions) {
    log.info("Checking " + oAction.getName())
    if (oAction.getName().equalsIgnoreCase("from status1 to status2")) {
        // validate and transition subtask
 def IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
        //is this line requared?
 issueInputParameters.setSkipScreenCheck(true)
        issueInputParameters.setComment("Testing comment")
        def validationResult = issueService.validateTransition(user, issue.getId(), oAction.getId(), issueInputParameters)
        if (validationResult.isValid()) {
            IssueService.IssueResult issueResult = issueService.transition(user, validationResult)
            if (!issueResult.isValid()) {
                log.warn("Failed to transition issue ${issue.key}, errors: ${issueResult.errorCollection}")
            }
            log.info("Successfully transition issue ${issue.key}, triggered by ${issue.id}")
        } else {
            String message = "Could not transition issue ${issue.key}, errors: ${validationResult.errorCollection}"
 log.warn(message)
            //The retry logic will pick up the exception
 throw new RuntimeException(message)
        }
        break;
    }
}
}catch(Throwable t){
    def message = "Failed to transition issue ${issue.key}"
 log.error(message)
}

Could you provide your code?

Thanks for looking at this. My code is

def expectedTransitionName="from status1 to status2"
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
log.info("Found workflow " + workflow.getDisplayName())
StepDescriptor oStep = workflow.getLinkedStep(issue.getStatus());
List<ActionDescriptor> oActions = oStep.getActions();
log.info("Found " + oActions.size() + " actions for " + workflow.getDisplayName())
try{}
	for (ActionDescriptor oAction : oActions) {
		log.info("Checking " + oAction.getName())
		if (oAction.getName().equalsIgnoreCase(expectedTransitionName)) {
			// validate and transition subtask
			def IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
			issueInputParameters.setSkipScreenCheck(true)
			issueInputParameters.setComment("Testing comment")
			def validationResult = issueService.validateTransition(user, issue.getId(), oAction.getId(), issueInputParameters)
			if (validationResult.isValid()) {
				def issueResult = issueService.transition(user, validationResult)
				if (!issueResult.isValid()) {
					log.warn("Failed to transition issue  ${issue.key}, errors: ${issueResult.errorCollection}")
				}
				log.info("Successfully transition issue ${issue.key}, triggered by ${issue.id}")
			} else {
				def message = "Could not transition issue ${issue.key}, errors: ${validationResult.errorCollection}"
				log.warn(message)
				//The retry logic will pick up the exception
				throw new RuntimeException(message)
			}
			break;
		}
	}
}catch(Throwable t){
	def message = "Failed to transition issue ${issue.key}"
	log.error(message)
}

 With the code, I am able to see the log output of "Successfully transition issue ${issue.key}, triggered by ${issue.id}". However the JIRA UI and the jiraissue table don't set the status to status2 ad described in my original question. 

Hello,

I have the same issue. Any news about it?

Thanks in advance

Sorry, it is long time ago and I don't remember what was the exact solution but I don't see such problem anymore. I changed my database isolation level from read_committed to read_committed_snapshot and it solved a lot of weird problems but I don't remember this is one of the them or not. 

I got the same problem and I solve it an other way

I put auto transition in the workflow (export workflow to xml, modify xml and import it)

sample in the xml : <action id="31" name="toNextPhase" auto="true">

and I control the transition by condition in the workflow

I wish this can help

 

an other post for auto transition Here

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Jan 15, 2019 in Statuspage

Introducing Statuspage Getting Started guides! First up: What is Statuspage?

Over the next several weeks we'll be sharing some of our Getting Started guides here in the community. Throughout this series of posts, we'd love to hear from customers and non-customers ab...

268 views 4 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you