Sending email through Script runner when custom field value updated

Jane January 6, 2022

Hi All, 

As a project manager, I want stakeholders to be informed by sending email when the endDate which is custom field is behind schedule.

I've tried multiple examples of code that sends an email from a listener and they all fail at filter the above requirement.

scriptRunner_01.png

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def
jiraBaseUrl = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)
def link="${jiraBaseUrl}/browse/${issue.key}"

def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "endDate"}
if (change) {
    log.debug "Old value(OriginalEndDate) : ${change.oldstring}"
    log.debug "New value(UpdatedEndDate) : ${change.newstring}"   
log.debug "Value changed by ${event.user} at ${event?.getChangeLog()?.created}"

// I want to send email above logs to stakeholders when New value(UpdatedEndDate) - Old value(OriginalEndDate) >= 1
}

When I've tried to create Send a custom email(non-issue events) for using CustomFieldUpdatedEvent, Every line seems to be needed as the validator complains. 

How can I send email Associating proper script with the event listener?

Thank you in advance for your help.

1 answer

0 votes
Florian PEREZ
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.
January 7, 2022

Hello,  

I think the subscribe filter feature can do this :

https://www.atlassian.com/blog/jira-software/jql-the-most-flexible-way-to-search-jira-3-of-4 

If not let me know and I'll help you to find a way to achieve want you want to do !  

Suggest an answer

Log in or Sign up to answer