Forums

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

Automatic scripted transition during issue creation process doesn't work?

Vladyslav Pilevych
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 7, 2022 edited
Good day!

 

Currently I'm developing a script that will transition created issue to appropriate status depending on the information if the custom field. Setup is the following:
=================================================
Open (1) >> To Manager Approve (11) >> MANAGER APPROVAL
Open (1) >> To Role Owner Approve (21) >> ROLE OWNER APPROVAL
Open (1) >> To Security Approve (31) >> SECURITY
Open (1) >> To work (41) >> IN PROGRESS
=================================================
The script is set as post-function on Create (1) transition. Here is a set-up of post-functions on Create (1) transition:
=================================================
1. Creates the issue originally.
2. Custom script post-function
.../postfunctios/prefillManagerFieldOnCreate.groovy
3. Custom script post-function
.../postfunctios/prefillFunctionalFieldsOnCreate.groovy
4. Re-index an issue to keep indexes in sync with the database.
5. Fire a Issue Created event that can be processed by the listeners.
6. Custom script post-function
.../postfunctios/initialTransitionToAppropriateApproval.groovy
=================================================
As you can see last script is related to transitioning issue and it is working properly (more on that a bit later), my question related to the transitioning approach.

 

So I know for certain that script executing transitioning method works perfectly. My question is connected to the building of transition. Method itself now looks like this:
private static void buildTransition(MutableIssue issueToTransition, ApplicationUser transitionUser, int actionId) {

IssueService issueService = ComponentAccessor.getIssueService()

TransitionOptions transitionOptions = new TransitionOptions.Builder()

.skipConditions()

.skipPermissions()

.skipValidators()

.build()

IssueService.TransitionValidationResult result = issueService.validateTransition(transitionUser,

issueToTransition.getId(),

actionId,

issueService.newIssueInputParameters(),

transitionOptions)

Logger.getLogger("result.isValid()").warn(result.isValid())

if (result.isValid()) {

issueService.transition(transitionUser, result)

} else {

Logger.getLogger("result.errorCollection").warn(result.errorCollection)

Logger.getLogger("Transition fail details:").warn(result.getErrorCollection().getErrors())

}


 

There are some modifications in the form of passed parameters but they are working fine. However, the result.isValid() when script is run on creation transition (Create(1)) returns "false". After some log-debugging I have the following:
=================================================
*2022-10-05 13:55:59,146+0300* http-nio-8080-exec-15 WARN v.p 835x27779x1 zg9cyu /secure/QuickCreateIssue.jspa [result.isValid()] false
*2022-10-05 13:55:59,146+0300* http-nio-8080-exec-15 WARN v.p 835x27779x1 zg9cyu /secure/QuickCreateIssue.jspa [result.errorCollection] Errors: {}
Error Messages: [It seems that you have tried to perform a workflow operation (Role Owner Approval) that is not valid for the current state of this issue (AMS-137). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.]
*2022-10-05 13:55:59,148+0300* http-nio-8080-exec-15 WARN v.p 835x27779x1 zg9cyu /secure/QuickCreateIssue.jspa [Transition fail details:] {}
=================================================

 

So transition can not be validated and thus issue is not transitioned when script is executed as post-function on "Create" transition.

 

As an alternative I've tried assigning this script to a listener that is triggered by "Create event" fired. And the behaviour is the same.

 

However, I've tested different set-up. I've created test loop transition (Open to Open), and put those scripts there. Then, on initial "Create" transition I've put a "Fast-track transition an issue" post-function built-in into ScriptRunner to trigger this loop transition. And this set-up works. So on initial "Create" fast-track post-function provided by plugin is triggering loop transition, which in turn executes scripts (along with automatic transition) and it works, and ticket without any additional actions goes to appropriate (defined in script) status via provided transition. Additionally, I've tested listener by adding (Issue updated) event and then updating any field in the ticket (without transitioning it) and this also worked.

 

So even, though I've found a workaround it is a little bit dirty and I would like to know if there are any other options and also to know if this is intended, and may be any other options I could try.

 

So wrapping up, my questions are:
1) Is this intended that right after ticket creation (when transition script is executed during "Create" transition, but after default and critical post-functions), [result.isValid()] is false. And also this goes for listener that is bounded to "Issue Created" event? In oher words is my set-up not possible?
2) Maybe it has something to do with the workflow? It is not initialised or smth.
3) If it is what are our options of achieving desired behaviour, avoiding creating excessive loop transitions.
4) Considering the fact that plugin provided "Fast-track transition" is working, is it possible to somehow incorporate it's implementation into our script and using it to perform a final action of the chain (transition itself)?
5) Maybe there are some other options on how we can perform the transition in a state that we need it to be performed?
6) I'm also currently in contact with scriptrunner support and they say sthat in fact scripted transition is not possible during issue creation process, however for now no specifics on why exactly its impossible. And I'm also curious then what different between ScriptRunners "Fast-track transition" and the transition I'm trying to build.

 

If any one has any answers or even just simply additional but slightly different information I would be glad to hear it. Or just even simply some experience that you can share. Cause at this point I'm trying to expand my understanding and knowledde on this matter.

 

Thanks all in advance!

0 answers

Suggest an answer

Log in or Sign up to answer