I need to send email if the label status and defect is in certain status.
How do I specify this in groovy
if the label status is = "red flag"
AND
if the defects status is "Critical"
Also want to send the defect description and summary in the email template.
I have noticed that in the email all the lines are combined in the html template. How do I separate out each items in the email and get the email in this format using script runner
Defects Summary:
Defects description:
Assignee:
Defect submitted Date :
Hi @Garden16_
Could you please provide more information, i.e. when do you want to trigger the email? Is it when the Issue transitions using a Post-Function or via a Listener when a change is detected?
If you want to use the Listener approach, you can use the Issue Updated event with something like this:-
import com.adaptavist.hapi.jira.mail.Mail
import com.atlassian.jira.issue.MutableIssue
def issue = event.issue as MutableIssue
def emailBody= """
<p>
<span style="color:black; font-size:20px;"> Defect Summary:</span> <span style="color:red; font-size:20px;">${issue.summary}</span><br/>
<span style="color:black; font-size:20px;">Defect Description:</span> <span style="color:red; font-size:20px;">${issue.description}</span><br/>
<span style="color:black; font-size:20px;">Assignee:</span> <span style="color:red; font-size:20px;">${issue.assignee}</span><br/>
<span style="color:black; font-size:20px;">Defect Submitted Date:</span> <span style="color:red; font-size:20px;">${issue.created}</span>
</p>
"""
if (issue.status.name == 'In Progress' ) {
issue.labels.each {
if (it.label == 'red_flag') {
Mail.send {
setHtml()
setTo('foo@example.com')
setSubject(issue.summary)
setBody(emailBody)
}
}
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Listener configuration for your reference:-
Below are a couple of test screenshots for your reference:-
1. First, an issue is created and is transitioned to In Progress, as shown in the screenshot below:-
2. Next, the Label field is updated, and the red_flag label is added, as shown in the screenshot below:-
3. As expected, the email is sent out with the required details ,as shown in the screenshot below:-
I hope this helps to solve your question. :-)
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
I was looking for post function for this feature. Trigger an email to dev leads (couple of them) when defect is assigned to one of the dev leads .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Garden16_
If you intend to do this via post-function, you can reuse the sample code I provided only with a monitor modification, i.e. the event variable is not required.
You can use ScriptRunner's Custom Script Post-Function with the updated working code below:-
import com.adaptavist.hapi.jira.mail.Mail
def emailBody= """
<p>
<span style="color:black; font-size:20px;"> Defect Summary:</span> <span style="color:red; font-size:20px;">${issue.summary}</span><br/>
<span style="color:black; font-size:20px;">Defect Description:</span> <span style="color:red; font-size:20px;">${issue.description}</span><br/>
<span style="color:black; font-size:20px;">Assignee:</span> <span style="color:red; font-size:20px;">${issue.assignee}</span><br/>
<span style="color:black; font-size:20px;">Defect Submitted Date:</span> <span style="color:red; font-size:20px;">${issue.created}</span>
</p>
"""
issue.labels.each {
if (it.label == 'red_flag') {
Mail.send {
setHtml()
setTo('foo@example.com')
setSubject(issue.summary)
setBody(emailBody)
}
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Post-Function configuration:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
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.