Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,202
Community Members
 
Community Events
165
Community Groups

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

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

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
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: AppLiger

This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity.    Atlassian:...

380 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you