Forums

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

Transition issue from a listener on Issue Created event

Viktor Kuzmychov
Contributor
May 2, 2022

While trying to transition an issue with a listener on Issue Created event getting error:

Errors: {}
    Error Messages: [It seems that you have tried to perform a workflow operation (gateway - to do --> to verify) that is not valid for the current state of this issue (QA-109070). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.]

Works perfectly fine on the same transition after issue is created. User has enough permissions to do it manually as well. Here's the code:

void execTransition(ApplicationUser currentUser, Issue issue, int transId){
def issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = new IssueInputParametersImpl()
issueInputParameters.setSkipScreenCheck(true)
TransitionOptions transitionOptions = new TransitionOptions.Builder().skipConditions().skipPermissions().skipValidators().build()
def transitionValidationResult = issueService.validateTransition(currentUser, issue.id, transId, issueInputParameters, transitionOptions)

if (transitionValidationResult.isValid()) {
IssueService.IssueResult trans = issueService.transition(currentUser, transitionValidationResult)
if(!trans.isValid()){
log.warn "Transition invalid"
trans.errorCollection.each {err ->
err.getErrorMessages().each {err1 ->
log.error err1.getProperties()
}
}
}
} else {
log.warn "Validation invalid"
transitionValidationResult.errorCollection.each {err ->
log.error err
}
}
}

 I saw Jamie's comment here but I still need to do it in listener

2 answers

1 accepted

3 votes
Answer accepted
Martin Bayer [MoroSystems, s.r.o.]
Community Champion
May 2, 2022

Hi @Viktor Kuzmychov the problem with listener is that issue is not created yet when this listener is executed. If you really need to do it in listener, you can try to execute the code with separate Thread with some Thread.sleep on the beginning of the code block but it is not nice... politely speaking :)

Viktor Kuzmychov
Contributor
May 2, 2022

@Martin Bayer [MoroSystems, s.r.o.] 

Thank you so much! you saved my day.

Also I don't get it. Create transition has Post Functions:

Create issue

Reindex issue

Fire event

 

I thought it is created by the time of event fired.

0 votes
Gray Watson July 10, 2023

I had real problems transitioning issues programmatically.  In one of my workflows it worked very well.  In another it would always leave the issue in a semi-transitioned state.  I wonder if somehow the task had not been fully updated or something in the database although I was doing it at the end of my post functions list.

I ended up using the Fast-Track post function and using a condition blob to set it up.  You can use any code and return true or false at the end to cause the transition.  If I needed additional functions called I would call it in code after the fast-track was done.

Hope this helps.

Suggest an answer

Log in or Sign up to answer