ScriptRunner get the old values of a customfield (script listener "send custom email")

 

Hi,
we tried to use the following code snippet in our email template to get the 
old values of a customfield (script listener, send a custom email)

 

<%
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Name of custom field"}
if (change) {
    out << 'Old: ' + change.oldstring + "\n"
    out << 'New: ' + change.newstring
}
%>

 

 

But we got an error

groovy.lang.MissingPropertyException: No such property: event for class: groovy.lang.Binding

at groovy.lang.Binding.getVariable(Binding.java:61)

at groovy.lang.Binding.getProperty(Binding.java:103)

 

JIRA version: 6.4.7

ScriptRunner version: 3.1.4



Can you please tell us what we do wrong?

 

Thank you very much in advance

 

best regards

Sebastian

 

 

6 answers

This widget could not be displayed.

you could try upgrading it and see if that fixes it, you're on a very old version...

This widget could not be displayed.

Thx, but this is also not the problem

we tested it on a other JIRA version

Jira: v7.1.7

ScriptRunner: 4.3.3
same error
This widget could not be displayed.

I have the same problem on 4.1.3.17.  I do not see the problem on an old system that is at 3.1.4.

This widget could not be displayed.

I worked around the problem in my script listener by avoiding use of event.  In my case, I wanted to listen to updates to see if issues were added or removed from a specific sprint.  I hard-coded the sprint id.  If someone can show me how to get the active sprint for a board, that would be great.

 

/*
 * Determines if the last change added or removed the item from the active sprint
 */
import org.apache.log4j.Logger
import org.apache.log4j.Level
 
def log = Logger.getLogger("com.xyz")
log.info("Condition Evaluation ...")
def ACTIVE_SPRINT = "194" //Hard code active sprint ID


// Get the last change ...
def changeHistoryManager = com.atlassian.jira.component.ComponentAccessor.getChangeHistoryManager()
def changeHistories = changeHistoryManager.getChangeHistories(issue);
def changeHistory = changeHistories.get(changeHistories.size()-1)
log.info("  changeHistory="+changeHistory)


// See if the last change contained a change to or from the active sprint
def changeItems =  changeHistory.getChangeItemBeans()
def added = false;
def removed = false;
changeItems.each() { com.atlassian.jira.issue.history.ChangeItemBean chgItem ->
    log.info("chgItem="+chgItem);
    def field = chgItem.getField()
	log.info("  field = " +field)
    if (field && field.equalsIgnoreCase("Sprint")) {
        log.info("    getFrom="+chgItem.getFrom());
        log.info("    getTo="+chgItem.getTo());
		removed =  chgItem.getFrom()==ACTIVE_SPRINT 
		added =  chgItem.getTo()==ACTIVE_SPRINT 
	}
}
log.info("Added?"+added+" or Removed?"+removed)

 

 

This widget could not be displayed.

Can you describe what you're trying to do here? Is it notify when an issue is added or removed from the active sprint?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

66 views 1 0
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