Script Listener Old Field Value

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

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

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?

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

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 :-)

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot