When a custom field is updated trigger a mail

MzM November 20, 2019

Hello All,

We'd like to improve the email by sending it to the custom field change for priority HIGH jira's..

Use Case : Custom filed 'Remediation Owner' is a Type - "Multi User" - when someone changes the value of that field (i.e., select another Owner) I need an e-mail to be sent out to the new Owner/s.

Note- this requirement is not for workflow status change or transition but only to custom filed value change at edit screen

 

Is there a way we can achieve this by script runner or any other supported way you guys have experienced, please share your thoughts..

 

Cheers

Mzm

 

 

6 answers

2 votes
MzM December 11, 2019

Forgot to mention/ share my findings I got it fixed by adding a small piece of customized code. It works perfectly as per the business requirement and it shoot email whenever ever value custom field change for priority issues. 

 

Below are the steps:

  • "Scriptrunner ->
  • Listener ->
  • Send a custom email ->
  • Events -> CustomFieldUpdatedEvent ->
  • Condition and Configuration -> {"issue.priority?.name == 'High' && cfValues['Remediation Stakeholders'] !=null"}
  • Email template -> "{add your mail template}"

Example

Dear User,

A Security Change Management has assigned/updated a High Priority Jira to you and requires your attention.

For more details, please refer to the link "$baseUrl/browse/${issue.key}"

<% if (mostRecentComment)

    out << "Last comment: " << mostRecentComment

%>

Best Regards,

${issue.reporter?.displayName}

  • Subject template -> "{add your subject template}"
  • To issue fields -> "{who need to notified, in my case Remediation Fields need to notify}".

 

Hope this helps if anyone looking for similar requirement.

Cheers

Mzm

1 vote
Daniel McCollum November 28, 2022

An updated version of solution that works on ScriptRunner 7.5.0 with Jira Server 9.0.0 - note minor change where dollar symbol is removed from email template, which then resolves script warning, enables preview of email template (if issue key entered), and allows email send when specified custom field is changes:

  1. "Scriptrunner (from  within Jira Administration)
  2. Listener (from various Scriptrunner tabs displayed horizontally)
  3. Send a custom email (select one with exact name, found 2nd from bottom of page)
  4. Note (title/description for listener)
  5. Applied To (chose a specific Jira project but Global is also an option)
  6. Events (select Issue Updated)
  7. Condition and Configuration (copy/paste example code below)
    • changeItems.any {
      it.get('field')=='ENTER FIELD NAME HERE'
      }
  8. Email template (copy/paste example code below and personalize mail template)
    • Hello,
      "ENTER FIELD NAME HERE" has been updated to ${cfValues['ENTER YOUR FIELD NAME']}
      <br>

      For more details, please refer to the link "https://baseURL/browse/${issue.key}"

      Regards,

      ${issue.reporter?.displayName}
  9. Subject template (copy/paste example code below)
    • Issue $issue - "ENTER FIELD NAME HERE" was modified
  10. To addresses
  11. To issue fields
    • field/individual/group requiring notification
  12.   ...
1 vote
Vladimir Horev _Raley_
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.
November 21, 2019

Hi Mzm,

You can solve this problem with our add-on Raley Notifications  

 

Here's how you approach it:

1) Create new Notification of type "issue updated"

2) Specify relevant project(s) and issue types(s)

3) In Fields updated section choose the custom field Remediation Owner

4) In JQL filter provide: priority = High

5) Provide subject value that make sense for your organization and in "To" section choose Remediation Owner again

6) Your message template will largely depend on your needs. Here's a simple basic that would do the thing:

===========================

Hello!<br/><br/>

Remediation owners have changed for $issue.key<br/>
New value is:</br>
#foreach ($ro in $issue.fields.customfield_12345)
$ro.displayName<br/>
#end

<br/><br/>
All the best,
Raley Notifications

===========================

 

Let us know if you need help setting this up.

Cheers,

Vladimir | RaleyApps

MzM November 22, 2019

Thanks Vladimir, hope this option should work for us!


I've had a quick glance, I found in Jira Atlassian Marketplace and this seems available for free/ testing whilst, I’m not sure, this trial version would meet our business requirement needs.. let me play around and explore.. will keep you posted.

0 votes
larry.lowe May 13, 2021

@Laura S Here is my solution, which currently works by sending an email when your specific custom field has been modified:

  • "Scriptrunner ->
  • Listener ->
  • Send a custom email ->
  • Events ->  Issue Updated (Do NOT use CustomFieldUpdatedEvent)
  • Condition and Configuration -> changeItems.any {
    it.get('field')=='YOUR FIELD NAME'
    }
  • Email template -> "{add your mail template}"

Example

Dear User,

"YOUR FIELD NAME" has been updated to ${cfValues['YOUR FIELD NAME']}
<br>
For more details, please refer to the link "$baseUrl/browse/${issue.key}"

Best Regards,

${issue.reporter?.displayName}

  • Subject template -> Issue $issue - "YOUR FIELD NAME" has been modified!
  • To issue fields -> "{who needs to be notified}".
0 votes
Laura S June 18, 2020

MzM,
I'm trying to use your solution but it's not working for me. I have a single select list called Resolver Group. Whenever that field is updated, I need an email notification sent to the selected Jira group e.g.

Resolver Group = Development => notification sent to everyone in jira-development-group
Resolver Group = Operations => notification sent to everyone in jira-operations-group

I created a listener > Manage apps > Scriptrunner > Listeners > Create Listeners > "Send a custom email (non-issue events) with the following settings: 
- Project: A
- Events: CustomFieldUpdatedEvent
- Condition: "cfValues['Resolver Group'] == 'Development'"
- Email template: A Jira ticket has been assigned to your Resolver Group.
                            For details, refer to the link "$baseURL/browse/$[issue.key]"
- Subject template: JiraNotice:
- To Users in Groups: jira-development-group

I set the Resolver Group in an Issue to "Development" but nothing happened. Listener history states "Has not run yet". Am I missing a step? Once I get this working, I'll need a little help to expand on the condition to account for 5 resolver groups.

thx,
LS

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.
June 18, 2020

If you want to do this in a couple clicks in a simple ui, you can use our app in place of ScriptRunner https://marketplace.atlassian.com/apps/1211069/notification-assistant-for-jira-email?hosting=server&tab=overview

Laura S June 19, 2020

Thank you for your quick response but I am limited to the existing plugins we have: Scriptrunner & JSU Automation Suite. 

0 votes
Payne
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.
November 21, 2019

Here is how we accomplished this for a similar scenario ... we removed the field from the edit screen, and in its place added a "circular" transition from a status back to itself. The transition uses a screen that has that one field on it. So now, rather than editing the issue, a user clicks the "Change ____" button, which pops up the screen with the field, and they change it there. Since it is a transition, we can then send an email to whoever needs it.

MzM November 22, 2019

Thanks Payne for the workaround though, much appreciated!

Sorry to inform you, this will not work for us as we need something at edit screen only that to for field change. Moreover, we've 3 diff type of remediation fields, business requirement demands to have shoot email only to remediation owners but not to others like reporter etc… and we cannot afford ending up adding w/flow transitions/ screens for the same.

Suggest an answer

Log in or Sign up to answer