Snippets

Adaptavist Jira Cloud - Script Listener - Send Notification On Condition

Created by Kristian Walker last modified
/*
* This example script listener script shows how to send a notification when the priority changes to highest.
* Note: This should be configured to run as the ScriptRunner Add-On User and on the Issue Updated Event
* Note: The condition to add to the Script Condition box is issue.priority.name == 'Highest'
* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
* license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or
* amended and must be included in any circumstances where the code snippet is shared by You or a third party." 
*/
 
 // This script should be configured to run as the ScriptRunner Add-On User and on the Issue Updated Event
 // In the conditions box the condition below must be added:
 // issue.priority.name == 'Highest'
 
 // Construct the message body
 def messageBody = "<p>The <b>${issue.key}</b> ticket has been set to the <b>Highest</b> priority.</p><p> Please action this issue immedietly</p>"

    // Send the email notification
    def sendNotification = post("/rest/api/2/issue/${issue.key}/notify")
            .header("Content-Type", "application/json")
            .body([
                    subject : "The priority was set to Highest on the ${issue.key} issue",
                    htmlBody: messageBody,
                    to      : [
                            assignee: issue.fields.assignee != null,
                            watchers: true,
                    ]
            ])
            .asString()

// Validate the notification sent correctly
assert sendNotification.status >= 200 && sendNotification.status < 300

// Log out the notification sent correctly
logger.info("Notification sent succesfully when the ${issue.key} was updated and the priority set to Highest");

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.