Skip to main content
Book your demo
Example scripts
To homepage
Jira
Cloud icon
Cloud

Send an email notification to the assignee and watchers of an issue when the reporter adds a comment.

Features
Listeners
Created 2 year(s) ago, Updated 2 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
groovy
// Get the reporter details as the issue property in the comment_created webhook only contains limited fields
def reporterDetails = get('/rest/api/2/issue/' + issue.key)
        .header('Content-Type', 'application/json')
        .asObject(Map)
        .body
        .fields
        .reporter

// Get the reporter accountId and displayName values
def reporterAccountId = reporterDetails.accountId
def reporterDisplayName = reporterDetails.displayName

// Get the commment authors accountId
def commentAuthorAccountId = comment.author.accountId

if (commentAuthorAccountId == reporterAccountId) {
    // Define the body of the notification using HTML to format it.
    def messageBody = "<p><b>${reporterDisplayName}</b> who is the reporter on the <b>${issue.key}</b> ticket has updated the issue.<p> <br/> <p> Please go and review the updates on the ticket.</p>"

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

    assert sendNotification.status == 204
}
Having an issue with this script?
Report it here