Hi,
I use the Scriptrunner Escalation Service to monitor 5 projects for overdue issues.
Then an email should be send to all projectrole members of "QMB" of the project, the issue occurs from.
I have the code to that for one specific project. Within this I use the projectkey to get the users and their mail adresses.
In my mind there needs to be a way for the script to look up the JQL results and only get the users of the QMB-projectrole for this exact issue.
Does anybody had a problem like this before?
My code
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import com.atlassian.jira.issue.issuetype.IssueType
import javax.ws.rs.core.Response
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.config.IssueTypeManager;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequest;
// Get all the mail addresses from the role members of a project
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRole = projectRoleManager.getProjectRole("QMB")
def project = ComponentAccessor.getProjectManager().getProjectObjByKey("TA")
def usersInRole = projectRoleManager.getProjectRoleActors(projectRole, project).getApplicationUsers()*.emailAddress.join(",")
// Create an email
def emailAddr = usersInRole
def subject = "[Audit]: Measure overdue"
def body = "Hello dear QMB,\nan action is overdue.\nPlease speak to the assignee.\n\nJIRA issue: https://xxx.com/browse/${issue.key} - ${issue.summary}.\n\nBest regards,\nAuditprocess-Workflow\n"
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);
} else {
// Problem getting the mail server from JIRA configuration, log this error
}
}
sendEmail (emailAddr, subject, body)
Lars