Script Listener Old Field Value

James Gralton June 20, 2013

I want send an email when the value of a custom field changes. I have created a Script Listener to do this on Issue Updated but want to include the old value in the e-mail. How do I do this?

Currently I have:

Condition: changeItems.any {it.get('field')=='Numeric Priority'}

E-Mail Template:

Issue: $issue - ${issue.summary}

New Numeric Priority: <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Numeric Priority")) %>

User: $currentUser.name

Description: ${issue.description}

I want to add Old Numeric Priority.

Thanks

2 answers

2 votes
Darly Senecal-Baptiste
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 20, 2013

Hi James:

Since this is an Updated Issue Listener, it is recomendable to use this code

/*Gather changed field at the Issue Updated*/
 def field = event.getChangeLog().getRelated('ChildChangeItem').find{it.field == "field_name"};

/*Gather field old value*/

def old_field_value = field.oldstring; //Old String of the field

/*Gather field new value*/
def new_field_value = field.newstring; //New String of the field

Hope that this piece of code may help you

James Gralton June 23, 2013

This sounds like this is what I am looking for. How do I use the above to extract the value into the e-mail template notation? Or is there another way to extract the value using what you have given me and append it to the e-mail?

Darly Senecal-Baptiste
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 23, 2013

James:

I have to confess that I didn't handle on notifications. But, if you want to send the old value to the notification template, you might ending up with a java class.

Good luck

Andreas K. March 18, 2015

Hi, I tried to use the nice code example above and incorporate it with a listener, but I cannot get it to work. Any ideas what I am doing wrong? {code:title=ExampleListener.groovy|borderStyle=solid} package com.acme.listener import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import org.apache.log4j.Logger class ExampleListener extends AbstractIssueEventListener { Logger log = Logger.getLogger("log4jLogger") @Override void workflowEvent(IssueEvent event) { log.debug "Custom Issue Update Event Listener Fired" /*Gather changed field at the Issue Updated*/ def field = event.getChangeLog().getRelated('ChildChangeItem').find{it.field == "Priority"}; /*Gather field old value*/ def old_field_value = field.oldvalue; //Old String of the field /*Gather field new value*/ def new_field_value = field.newvalue; //New String of the field if ((new_field_value == 1).and(old_field_value != 1)) { log.debug "Custom Issue Update Event Listener Fired - Changed to J0" } else { log.debug "Custom Issue Update Event Listener Fired - Changed to some other priority" } } } {code} Thx :-)

0 votes
Randall Robertson
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 20, 2013
The standard notification template includes the old value and the new value. Can you check the default template? Or you could just use the standard notification rather than write your own.

Suggest an answer

Log in or Sign up to answer