Order of execution for ScriptRunner Listeners

I have 2 custom script Listeners. One Listener will create a custom ID for a JIRA issue. The other Listener will update another system (AccuRev) with information from the JIRA issue. I want both of these to run on Issue Created events but I want to make sure the ID Listener runs before the AccuRev Listener runs. 

I am using JIRA 7.3.6. When I go to the Script Listeners pane, I have the ID Listener before the AccuRev Listener. Is that order related to any execution order?


1 answer

1 accepted

0 votes
Answer accepted

i George, 

You cannot set the order that the listeners will get executed which means if you have both your listeners to listen for the issue created you will never be sure which of them will run first.

What you can do tho is to have a listener that will listen for the issue created event - I beleive in your case this will be the one that will create a custom ID for JIRA and then your AccuRev listener that will listen for a custom event.

So the question now is how to trigger the custom event you created. The solution is, in the script you have for the create a custom ID for JIRA listener to programmatically trigger the custom event. 

This is how the script for the create a custom ID for JIRA listener will look like 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser

// Listener that listens to an Issue Created event

def issue = event.issue
def asUser = ComponentAccessor.getUserManager().getUserByKey("admin")

log.debug "Listener that do something with the ID triggered"

// code here that do something with the id

// get the id of custom the event you want to trigger
def eventId = ComponentAccessor.eventTypeManager.eventTypes.find {it.name == "Issue Id Created"}?.id

// call the method that will raise the given event, so it will be caught by the next listener
triggerEvent(issue, asUser, eventId)

* A method that raises an event
* @param issue The issue that the event will raise for
* @param user The user that the event will raised from
* @param eventId The event id to raise
def triggerEvent (Issue issue, ApplicationUser user, Long eventId) {
def issueEventManager = ComponentAccessor.getIssueEventManager()
def issueEventFactory = ComponentAccessor.getComponent(IssueEventBundleFactory)

def eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, user, eventId, true)) as IssueEventBundle

And then you will have the listener that will listens to  the custom event that raised form the previous script....

Hope that makes sense, shout if you need further assistance ...

Kind regards, 


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


251 views 0 6
Read article

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