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.
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.