Hi Friends,
I am new to groovy scripting and need your help to learn
I need to create a Listener to send an custom email when following 2 condition is met
-Thankyou in advance
This should get you started:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.server.MailServerManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.mail.Email;
import com.atlassian.mail.server.SMTPMailServer;
def mailManager = ComponentLocator.getComponent(MailServerManager)
def issueManager = ComponentAccessor.getIssueManager()
SMTPMailServer mailServer = mailManager.getDefaultSMTPMailServer()
def userEmail = "user@email.com"
//Who should the email be sent to?
Email email = new Email("${userEmail}");
//def issue = issueManager.getIssueByCurrentKey("ISSUE-7")
//uncomment this line to test the script against a specific issue
def customFieldValue = issue.getCustomFieldValue(10500)
//Change to the value of the custom field ID
if ((customFieldValue.toString() == "In Review") && issue.issueType == "SW system Engineering") {
email.setSubject("Issue Detected");
email.setBody("Issue ${issue.key} has a custom field with a value of ${customFieldValue.toString()}, and had an issue type of ${issue.issueType}");
mailServer.send(email);
}
def customFieldValue = issue.getCustomFieldValue(10500)
This part won't work, as per https://docs.atlassian.com/software/jira/docs/api/9.8.1/com/atlassian/jira/issue/Issue.html#getCustomFieldValue-com.atlassian.jira.issue.fields.CustomField- it expects a CustomField parameter.
So just need to change this to
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject("customfield_11111") //obviously change this
def customFieldValue = issue.getCustomFieldValue(customField)
This comparison
customFieldValue.toString() == "In Review"
I think works, I believe that the option implements toString() to return the value, but in case it doesn't it would be "customFieldValue.getValue() == "In Review", but I think it's not necessary, think that the toString() works as is but I don't have the source code on hands right now to verify, so just mentioning this in case..
other than that lgtm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thankyou so much Ken and Redak.
this works with slight modification
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.