Send an email when user custom field is updated - to the corresponding user's email

Lara Arthur October 20, 2021

Hi there Atlassian Community,

I have a user custom field called 'Champion/ Owner'. I want to set up a ScriptRunner listener that will send an automated email to the user listed in the 'Champion/ Owner' field when that field is updated.

  1. 'Champion/ Owner' field currently has a Jira user populated
  2. 'Champion/ Owner' field is updated with a different Jira user
  3. Email gets sent to the new 'Champion/ Owner' user's corresponding email

I've found and put together the following in the Condition area:

import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent

def change = CustomFieldUpdatedEvent.find { it['field']=='Champion' }
def newValue = change['newvalue']
def oldValue = change['oldvalue']

this isn't throwing any errors, but I don't know how to add the send email 'To' part of it.

I found some older posts that say to just put the "customfield_num" in the 'To' piece of the email listener or versions of that and everything I add in there throws an error  "These don't look like valid email addresses:"

How do I set up the rest of either the condition, or what do I put in the 'To' line to have the email sent to the the corresponding user email?

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 23, 2021

Maybe it's because of a different version of Jira (i'm on 8.13), but I don't have access to that specific event.

But without trying it, my initial assumption is that this event is about the Custom Field configuration itself being changed, not an issue's custom field value changing. 
Looking at the 8.20 documentation for that event, I think my assumption bears out 

I think what you really want, is to use the "IssueUpdatedEvent" and then look at the list of fields in the ChangeLog.

/**
* Condition to test if a field was modifid
*/
import com.atlassian.jira.component.ComponentAccessor
ComponentAccessor.changeHistoryManager
def fieldName = 'Champion/ Owner'
def changeLog = event.changeLog
if(changeLog){
def changeItems = changeHistoryManager.getChangeHistoryById(changeLog.id as Long).changeItemBeans
return changeItems.any{it.field == fieldName)
}
return false

As for actually sending the email, I'm assuming you're using this scriptrunner built-in listener ?

If so, you should be able to just specify the Champion/Owner in the "To Issue fields" part of the configuration. If you can't find your field in that lookup, then your field is not of the right type.

If you enter "user" information, that field should be a "User Picker" custom field.

If that's not the case, You'll need to write some code to find the correct user from that field and extract the user's email.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events