ScriptRunner error in custom email listener

When executing a custom email listener listener the below error is displayed in the logs and the email is never sent. When I run the preview function, the email is generated correctly. I attempted to put logging statements in the templates but the import statements generated errors. Ho can I go about debugging this?

Versions

JIRA 6.4.14

ScriptRunner 4.1.3.24

Email Template

Your request <A href="$baseurl/browse/$issue">$issue</A> has been submitted successfully. The aligned ESM <%
    String esmKeyString = issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("ESM's Name"));
    def (esmKey, value2) = esmKeyString.tokenize( '(' )
    def esmName = componentManager.getUserUtil().getUserByKey(esmKey).getDisplayName()
    out << esmName;
%> will be contacting you shortly.

Subject template

Issue $issue: A <%
    String companyName = issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Company Name"));
    out << companyName;
%> request has been submitted successfully

Error

Time (on server): Fri Jan 27 2017 15:51:25 GMT-0500 (Eastern Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-01-27 14:51:25,773 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2017-01-27 14:51:25,773 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, script: com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail
java.lang.NullPointerException: Cannot invoke method tokenize() on null object
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.constructMail(SendCustomEmail.groovy:477)
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMail$0.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.constructMailWithConditionResult(SendCustomEmail.groovy:457)
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMailWithConditionResult.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.doScript(SendCustomEmail.groovy:553)

2 answers

This widget could not be displayed.

You'd be better off putting this in the configuration so you can inject it in as a variable, and handle null as you wish.

https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_additional_configuration_in_emails

This widget could not be displayed.
Vasiliy Zverev Community Champion Jan 27, 2017

Main trouble is that variable "esmKeyString" is null. Since NullPointerExeption is raised.

It is null because there is no value for customfiled "ESM's Name"

There are two options to do

  1. make this field mandatory
  2. add try/catch block for NullPointerExeption

 

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 Wednesday 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...

139 views 2 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