Send E-mail Notification after editing a specific custom field in issue edit screen

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012

Hi there,

I've been looking around for a while and can't find a real solution. We have implemented a custom field called "supervisor" (user picker). As sonn as someone changes the value of that field (selects another supervisor) I need an e-mail sent to the new supervisor.

Those are the posts I've found so far:

https://answers.atlassian.com/questions/16652/trigger-email-based-on-custom-field-value

https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Firesaneventwhenconditionistrue

http://old.nabble.com/trigger-email-based-on-custom-field-value-td29452403.html

https://studio.plugins.atlassian.com/wiki/display/GRV/Post+Functions#PostFunctions-SendEmailWhenBlockerReported

As far as I can tell the problem is mainly being addressed via post-functions as part of the groovy script plugin.

The problem is, that I would need a transition to fire an event, a post-function etc. My customer wants the email to be sent right away without the need of a workflow transition. Would it be possible to execute the code provided in Jamies examples of the script runner using the behaviours plugin (in real time) ?

Thanks for any hints...

Cheers Christian

4 answers

1 accepted

3 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2012

I think you need to use the send email listener with a condition that the field has changed, and is the value you want to check for.

Using the behaviours plugin is all well and good, but it will send the mail as soon as the value is changed, and before the issue is even saved. I know they wanted it sent "as soon as" but that's overkill. If they toggle it multiple times then multiple emails will be sent.

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2012

Hey, thanks for the advice. I've never created a listener. Are those the right places I have to start from? Or can I modify an existing listener?

https://confluence.atlassian.com/display/JIRA/Listeners

https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Writing+JIRA+event+listeners+with+the+atlassian-event+library

Cheers

Christian

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2012

Yup, those are the ones!

5 votes
sandeepkolte March 19, 2018

My solution to notify someone when a custom JIRA field is modified is to use the Filter and Subscriptions.

E.g. If I needed a notification sent out whenever our custom field ‘Test Notes’ is updated, I would create a filter such as says ‘Test Notes Updated in last 1 hour’ with following search criteria

 "Test Notes" is not EMPTY AND updated > -1h

 Next, save the filter. Search your saved filter in Manage Filters. Click Subscribe under Subscriptions column. Add subscription using the on screen options for Recipients, Schedule, Interval etc. If you need one or more people to receive the notifications, create a JIRA group under JIRA User Management options / Groups tab on the left. e.g. jira-testers: Once you add the subscription, that’s it, it is not instantaneous as you are asking it to notify everything updated in last one hour (1h in the filter above) but you can make it so if you want by changing your filter.

 SK

John Nguyen July 1, 2019

Your solution is not triggered by an event.  The email will send anyway - based on pre-set schedules - whether the update of last hour does or does not occurs.

  In other words, if there was no change took place in the last hour, the email notification will send anyway.

Matthew Frassetti September 14, 2020

John, there is an option to disable sending the email if the query has no results.

Like Mark de Bont [Terberg] likes this
0 votes
Boris Berenberg - Atlas Authority
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 30, 2020

8 years later, if you are looking for an easy way to handle this without having to write custom listeners, Notification Assistant for Jira supports sending notifications on Field Edit.

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012

I think this is possible using Behaviours you will just need to paste the same script with some additional packages provided by behaviours plugin as a server side script on the "supervisor" field.

This script will get fired whenever the supervisor field is changed.

Note : it will even get fired if someone changes the field and again change the field and everytime when changing the field before submitting

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import org.apache.log4j.Category
 

 
FormField supervisor = getFieldById(fieldChanged)
ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
 
if (mailServer) {
    
        Email email = new Email("someuser@example.com") // Set the TO address, optionally CC and BCC
        email.setSubject("Blocking issue raised by ${issue.getReporter().getFullName()}: ${issue.summary}") // todo: check the subject value
        String content = "Construct your body here.";  //TODO: Set email's body.
        email.setBody(content)
        mailServer.send(email)
    
}
else {
    log.error("No SMTP mail server defined")
}

Try the above script , enable logging .

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012

I'll try the script tomorrow. Thanks! Just one more thing:-) The Email TO-address in this example is static. I'd need to dynamically populate that with the newly selected supervisor's mail address. Any ideas?

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012

I dont think that will be a big challenge we will have to get the value in the supervisor field then get the email id of that user , first test with a static email id .

Suggest an answer

Log in or Sign up to answer