Guest Contributor: Justin Griffin
If you have been using Groovy to trigger custom notifications in Jira, things are about to get a whole lot simpler. With Simple Issue Language, or SIL™ for short, what may have taken half a dozen lines of code to write with Groovy, can now be accomplished with only a single line. In this post, I'll walk you through what SIL is, how it works, and how to set it up to trigger a custom notification.
The Scoop on SIL
SIL is a powerful, independent scripting language often used in customizations made to Jira Software applications, and it can be used as a replacement for Groovy scripts, which are often tedious to write and challenging to maintain at scale. The SIL scripting language is packaged with the Power Scripts™ for Jira.
Using SIL, it’s possible to reduce the amount of code necessary to trigger a custom notification from as many as half a dozen to as little as one because a Jira-specific interpreter comes packaged with the app that simplifies the complex routines and methods written with Groovy and traditional Jira Java API's. In Groovy, you must import Java packages, create instances of objects, and execute methods to simply get the context of an issue.
With a SIL script, upon successful execution, it is already running in the context of the current issue, and accessing its properties is as simple as typing 'id' for the issue id, or 'summary' for the issue summary. With this simplicity, you can focus on the business logic of operating on the issue fields instead of accessing the fields before modifying their values.
SIL scripts can be executed in a variety of ways, such as during a workflow post function, or with the help of a SIL Listener, they can triggered by an event. A workflow post function executes each time a status is changed, whereas a Listener executes each time an event is fired.
In the example below, we are assuming you have an existing SIL Listener configured that executes a script each time an issue is created.
Create a Custom Event
To send a custom notification from a SIL script, first, you will need to configure a custom event in Jira. Navigate to Jira Adminstration > System > Events and scroll to the bottom of the page to add a new event. Because we want to send a notification from a SIL Listener configured to execute after the Issue Created event is fired, you should select the Issue Created template.
Raise Custom Event with SIL Script
To trigger the actual notification, navigate to Jira Administration > Manage Apps > SIL Manager and open your custom script. Add the following line of code to raise an event during the script execution.
Take notice of the parameters, as these should be changed depending on your needs.
|Custom Issue Created||The title of the custom event we created|
|key||The key of the current issue|
|admin-user||The user to run the event as|
Each time this SIL Listener script is executed, an additional Issue Created email will be sent. With this basic template, you can expand the logic to send notifications for non-standard events. For instance, imagine your SIL script accesses another project and copies the Watchers from one issue to the new issue that was just created in another project.
You may notice the new Watchers are successfully added to the issue. However, by default the standard Issue Created email will not be sent to these new Watchers. Although they were added to the issue, they were added after the Issue Created event fired. You can use the Raise Event() call above to send a notification to the new Watchers, and your users, both standard and those added from the script, will all receive the same issue created notification.