Snippets

Adaptavist Jira Cloud - Post Function - Send Notification On Condition

Created by Kristian Walker last modified
/*
* This example post function script shows how to send a notification an issue is transition with the priority of Highest.
* Note: This script should be configured to run as the ScriptRunner Add-On User and use a Run Script Post Function
* Note: The condition to add to the Script Condition box is issue.fields.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 use a Run Script Post Function
 // In the conditions box the condition below must be added:
 // issue.fields.priority.name == "Highest"
 
 // Construct the message body
def messageBody = "<p>The <b>${issue.key}</b> ticket has been transitioned with the <b>Highest</b> priority to the ${issue.fields.status.name} status.</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 transitioned with the priority set to Highest");

Comments (0)

HTTPS SSH

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