Script Listeners
Migrating from ScriptRunner for Jira Server/DC to Cloud? Check out our ScriptRunner Migration to Cloud section. |
Before you start
Visit ScriptRunner HQ to see example scripts. | |
Learn about event-based automating with Script Listeners. |
The condition script will be evaluated before your code is executed. In the case where a value other than true is returned then we get a false result, and the code will not execute. The condition is evaluated using the Jira Expression Framework.
You can refer to our Example Restrictions and Validators page for further details.
As a result of Atlassian's Transition to Forge Events and Missing Event Properties, it's important that you review and update any Script Listeners that depend on the missing properties. There is no workaround for retrieving these properties via the Atlassian REST API. Therefore, to ensure your scripts do not break after the transition, they need to be removed from any scripts that use them.
What are Script Listeners?
A listener is an automated procedure or function in ScriptRunner that waits (or listens) for a specific event to occur in Jira and then carries out an action if the event occurs. Listeners sit on your instance and wait for a webhook event to happen before executing the listener script. Webhooks are triggered after an action has occurred in Jira, such as when a space is created or a work item is updated.
Scripted Fields work items are updated after a script is executed, triggering an issue_updated webhook event in Jira. This event is sent to ScriptRunner, but does not cause the script to run again or trigger any associated script listeners configured for work item update events.
Script Listeners that update work items will trigger an issue_updated webhook event in Jira, which is then sent to ScriptRunner. If scripted fields are configured for the updated work items, they execute once, updating the work item and triggering another issue_updated webhook event without requiring any further processing.
How to use Script Listeners
You may want to use a Script Listener to:
- Populate a space with initial work items when it is created.
- Post a message to Slack when a work item is created.
- Store story points of sub-tasks against the parent work item.
Previously, it was important to ensure that your scripts did not inadvertently trigger events your script listener was listening for, as this risked causing an infinite loop. However, now self-triggering scripts can no longer execute after 10 runs. This restriction means that if a script creates an event that results in the same script running again, ScriptRunner will count the number of times this occurs and reject the 11th run. If this happens, you will see a log message informing you that Scriptrunner has cut off a self-triggering script loop.
Script Listeners and Post Functions
The crucial difference between Script Listeners and Post Functions is that the latter rely on a transition change, whereas the former depend on an event occurring, which can happen at any time.
Script Listeners give you more control over automated actions than you would get with a Post Function.
For example, whenever there is a Critical level priority work item in a specific space, you want a message to be sent to a Slack channel. If you use a post function to do this, the event will fire only after a transition, not when the work item is edited. Therefore, if the priority of the work item were edited to Critical, the post function would not catch it until after the work item had been transitioned. To achieve this use case, you would use a listener to catch a change in priority when it happens.
Create a Script Listener
Edit a Script Listener
Related content
- Take our ScriptRunner Tour.
- See our Example Script Listeners.