I want to setup a ScriptRunner Listener that sends a custom email to certain people when '@ Data Export Control' is added in a Comment.
I have the email subject and template setup ok, but the 'Condition and Configuration' I can't get to work.
I currently have:-
"import com.atlassian.jira.event.comment.CommentEvent
Hello @Karl Samson
Here's a simplified version of what the script might look like:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.comment.CommentEvent
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.mail.Email
import com.atlassian.mail.server.SMTPMailServer
// Your ScriptRunner listener should listen for CommentEvent
if (event instanceof CommentEvent) {
def commentEvent = event as CommentEvent
def comment = commentEvent.getComment()
def commentBody = comment.getBody()
// Check if the comment contains the specific keyword
if (commentBody.contains("@Data Export Control")) {
def issue = comment.getIssue()
def recipient = "email@example.com" // Define the recipient's email address
def subject = "Your Email Subject"
def body = "Your Email Template"
// Sending email
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(recipient)
email.setSubject(subject)
email.setBody(body)
mailServer.send(email)
} else {
log.warn("No SMTP Mail Server configured in JIRA.")
}
}
}
A few things to note:
"email@example.com"
, "Your Email Subject"
, and "Your Email Template"
with the actual email address, subject, and body template you want to use.contains
method is case-sensitive. You may want to use toLowerCase()
or a similar method for a case-insensitive match.If this answer has resolved your issue or helped you in any way, kindly consider accepting it by clicking on the "Accept" button. This helps other community members find similar solutions more efficiently in the future.
Hey Eugenio, that's great! More than I was expecting in terms of an answer, thank you very much!
I'll need to modify it slightly in order for it to work in context. But will publish the final working solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Eugenio, so I'm wanting to adapt the script for a Custom Email Listener. But the script won't compile? Can you suggest why please?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.comment.CommentEvent
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.mail.Email
import com.atlassian.mail.server.SMTPMailServer
// Your ScriptRunner listener should listen for CommentEvent
if (event instanceof CommentEvent) {
def commentEvent = event as CommentEvent
def comment = commentEvent.getComment()
def commentBody = comment.getBody()
// Check if the comment contains the specific keyword
if (commentBody.contains("@Data Export Control"))
The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script6.groovy: 15: Unexpected input: '{\r\ndef commentEvent = event as CommentEvent\r\ndef comment = commentEvent.getComment()\r\ndef commentBody = comment.getBody()\r\n\r\n// Check if the comment contains the specific keyword\r\nif (commentBody.contains("@F-35 Data Export Control"))' @ line 15, column 55.
("@Data Export Control"))
Email Template:- ^
Notification of Task ${issue.key}
${issue.key} $issue.summary
Description: $issue.description
https://jira.usp.greenlnk.net/browse/${issue.key}
Regards,
${issue.reporter?.displayName}
Email Subject:-
Notification of Task ${issue.key}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.