Example scripts
To homepage
Jira

Notify Approvers of Pending Approvals via Email
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.0 - 8.17)

ScriptRunner For Jira (6.30.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.mail.Email
import groovy.json.JsonSlurper
import groovy.xml.MarkupBuilder
def key = issue.key
def applicationProperties = ComponentAccessor.applicationProperties
def mailServerManager = ComponentAccessor.mailServerManager
def mailServer = mailServerManager.defaultSMTPMailServer
final def host = applicationProperties.getString('jira.baseurl')
final def restEndpointName = 'getApprovers'
def baseUrl = "${host}/rest/scriptrunner/latest/custom/${restEndpointName}?issueKey=${key}"
def response = baseUrl.toURL().text
def json = new JsonSlurper().parseText(response)
def artifacts = json.collect()
def emailBody = new StringWriter()
def html = new MarkupBuilder(emailBody)
def mkp = html.mkp
html.html {
body {
p {
mkp.yield 'Awaiting your Approval for this Issue'
a(href: "${host}/browse/${key}", key.toString())
}
}
}
artifacts.findAll {
def emailAddress = it.toString()
def subject = 'Approval Reminder'
def body = emailBody.toString()
def email = new Email(emailAddress)
email.setSubject(subject)
email.setBody(body)
email.setMimeType('text/html')
def threadClassLoader = Thread.currentThread().contextClassLoader
Thread.currentThread().contextClassLoader = mailServer.class.classLoader
mailServer.send(email)
Thread.currentThread().contextClassLoader = threadClassLoader
}
Having an issue with this script?
Report it here