Use Scriptrunner to send one email collating all issues assigned to user

Adam Gaudry
Contributor
February 19, 2018

Hi there

I'm trying to use the escalation service to notify assignees when they have tickets more than 5 days old. Currently, the JQL/script I am using would send an email for every single ticket found by the JQL.

Is there any way of sending any assignees found by the JQL a single email, with a list of all applicable tickets?

The script I am using is this:

import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.component.ComponentAccessor;

def subject = "Please review and update aged ticket ${issue.key}"
def body = "Hi ${issue.assignee.displayName} \n\nYou are receiving this email because the issue https://jira.aws.telegraph.co.uk/browse/${issue.key} - ${issue.summary}, is unresolved and more than 5 days old. \n\nPlease review and, where possible, resolve this issue."
def emailAddr = issue.getAssignee().getEmailAddress()

def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body);
mailServer.send(email);
}

sendEmail (emailAddr, subject, body)

 

1 answer

1 accepted

1 vote
Answer accepted
Ivan Tovbin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2018

Hi Adam,

Assuming that at some point in your code you are getting an array of issues returned by your JQL search, you can construct a multi-line string which would list the links to every issue you find and then use that string in your email body, like so:

String issueLinks = "https://yourjira.com/browse/${issuesFromJql[0].getKey()}"
if (issuesFromJql.size() > 1){
for (int i = 1; i < issuesFromJql.size(); i++){
issueLinks = issueLinks + "${System.lineSeparator()}https://yourjira.com/browse/${issuesFromJql[i].getKey()}"
}
}
String body = """
Hi, here's a list of your issues:
${issueLinks}
"""
Adam Gaudry
Contributor
May 17, 2018

Thanks Ivan, I will investigate your suggestion!

Suggest an answer

Log in or Sign up to answer