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

Zhiyong Liu December 21, 2016

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

1 vote
Vasiliy Zverev
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.
December 22, 2016

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)
}
0 votes
Yann Follet September 13, 2018

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

0 votes
Innovación - Proyectos Compartidos December 1, 2017

Hello,

I have the same issue. Any news about it?

Thanks in advance

Zhiyong Liu December 6, 2017

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. 

0 votes
Zhiyong Liu December 22, 2016

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&lt;ActionDescriptor&gt; 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. 

0 votes
Vasiliy Zverev
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.
December 21, 2016

Could you provide your code?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events