Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

need to send email if the label status and defect is in certain status.

Garden16_ November 13, 2023

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 :

 

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2023

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:-

listener_configuration.png

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:-

test2.png

2. Next, the Label field is updated, and the red_flag label is added, as shown in the screenshot below:-test3.png

3. As expected, the email is sent out with the required details ,as shown in the screenshot below:-

test1.png

I hope this helps to solve your question. :-)

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Garden16_ November 27, 2023

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 .

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 3, 2023

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:-

post_function_config.png

 

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

TAGS
AUG Leaders

Atlassian Community Events