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
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,308 views 2 7
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