Dear Community,
could some1 please help me. We are trying to sent a notification to participants. We already have a script to add participants to issue when field contains value.
For your requirement, I suggest looking at this Adaptavist Library Example which uses the REST Endpoint to get the email addresses of the participants.
Once the Rest Endpoint is set, you can run something like this to send the emails:-
import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.component.ComponentAccessor
import com.adaptavist.hapi.jira.mail.Mail
import groovy.json.JsonSlurper
final def restEndpointName = 'getParticipantsEmail'
def applicationProperties = ComponentAccessor.applicationProperties
def baseUrl = applicationProperties.getString('jira.baseurl')
def issue = Issues.getByKey('ST-3')
def hostUrl = "${baseUrl}/rest/scriptrunner/latest/custom/${restEndpointName}?issueKey=${issue.key}"
Mail.send {
def response = hostUrl.toURL().text
def json = new JsonSlurper().parseText(response)
def artifacts = json.collect().sort()
setHtml()
setTo(artifacts.toString().replace('[','').replace(']','').trim())
setFrom('reminder@mail.com')
setFromName('Jira')
setSubject('Reminder')
setBody("<html><h3>Summary: ${issue.summary}</h3><br/><h3>Description: ${issue.description}</h3>")
}
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
For more information on how to use the Mail class, please refer to the ScriptRunner HAPI Documentation.
Please also ensure that you upgrade your ScriptRunner to the latest release, i.e. 7.13.0 to be able to use HAPI.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
Hi Martin.
as I see, you are already firing an ISSUE_UPDATED event; therefore you can configure a notification to be sent out in your JIRA notification scheme.
Or if you would like to have more customization options, you can try the Email This Issue app.
If you are already trying that app and would like to keep everything in script you are going to need the EmailService Interface: com.metainf.jira.plugin.emailissue.api.EmailService
This Interface has a sendEmail method that requires an EmailDefinition as a parameter that contains all the necessary data for your email such as recipients subject and email body.
This definition uses String Lists to store the recipients, so you would need to extract the email addresses from each of your participants.
You can see the full documentation of this feature here.
Cheers,
Levi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.