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 Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,266 views 5 10
Read article

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