Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Transition an Issue with custom field

fuzzelmukkel May 22, 2019

Hi Community,

 

I encounter a problem (the script failing ungracefully) when trying to transition an issue from ScriptRunner.

There is no error code, it is like the script is just abandoning at issueService.transition(). I get the same behaviour when using issueManager.updateIssue().

Funnily the issue gets transitioned but the script fails to continue. The try/catch-block fails too.

I have another issue (other project), where the issueService.validateTransition() is causing the fail.

 

Could it be that there is an error with custom fields and newIssueInputParameters?

 

This is my code:

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

def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def issue = issueService.getIssue(user, "FOSS-14")
if (!issue.isValid()) {
log.error("invalid issue")
return
}
issue = issue.issue

log.error("0")
try {
def action = 21

def issueInputParameters = issueService.newIssueInputParameters()

log.error("1/2")

def validationResult = issueService.validateTransition(user, issue.id, action, issueInputParameters)

log.error("1")

if (!validationResult.isValid()) {
log.error("invalid transition")
return
}

log.error("2")

def transitionResult = issueService.transition(user, validationResult)

log.error("3")

if (!transitionResult.isValid()) {
log.error("failed transition")
return
}
} catch (Exception e) {
log.error(e)
}

log.error("warning")

 

Output is:

2019-05-22 15:26:32,459 ERROR [runner.ScriptRunnerImpl]: 0 
2019-05-22 15:26:32,459 ERROR [runner.ScriptRunnerImpl]: 1/2
2019-05-22 15:26:32,461 ERROR [runner.ScriptRunnerImpl]: 1
2019-05-22 15:26:32,461 ERROR [runner.ScriptRunnerImpl]: 2

 

Thanks for any input!

 

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Champion
May 22, 2019

Hi @fuzzelmukkel ,

Are you using this script in the create postfunction ? Caused me issues before.

Anyway this is the code I use to transition an issue and it has been working fine so far :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.util.JiraUtils

def transitionId = 21

WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue);
workflowTransitionUtil.setUserkey(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getKey())
workflowTransitionUtil.setAction(transitionId);
workflowTransitionUtil.progress();

Antoine

fuzzelmukkel May 23, 2019

Works very smoothly, thanks!

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer