Script Runner Custom email error

Script Runner Custom Email

<p>
You have been assigned as a Tech Resource to $issue.issueType.name <a href="$baseUrl/browse/<% out << issue.key %>">$issue</a> with priority <% out << issue.priority?.name %>.
<br></br>
<% 
def rendererManager = com.atlassian.jira.component.ComponentAccessor.getComponent( com.atlassian.jira.issue.RendererManager.class)
def fieldLayoutItem = com.atlassian.jira.component.ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("description")
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
String desc = renderer.render(issue.description, null)
String description = "Description: " + desc 
%>
$description
<br></br>
Last Comment:<br>
<% out << componentManager.commentManager.getComments(issue)?.last()?.authorUser.displayName %> –
<% out << componentManager.commentManager.getComments(issue)?.last()?.body %>
</p>

 

Error

Exception in thread "Thread-6132" groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
GStringTemplateScript31.groovy: 2: unexpected char: '\' @ line 2, column 57.
   n { out -> out << """($issue) \CPP\Dicse

 

Description has \CPP\code in it which it appears to be erroring on and not sending an email.  Is there a way to fix this?

4 answers

Hi Kevin, I was trying to reproduce the error but your code works fine for me (having as a description a simple helloWorld code in C++). You may encounter a problem if there are no comments and you invoke the .last in an empty list. You can use the .empty to determine if the list is empty (the Safe Navigation operator ? only checks for null) Also you should use the ComponentAccessor instead of the componentManager in order to get the commentManager.

So with the .empty you would check to see if it is empty 1st before running the comment part?

Hey Kevin, def commentsList = [] lastUserCommented = commentsList?.last()?.authorUser?.displayName Results to: Error Cannot access last() element from an empty List Therefore you can use def commentsList = [] if (!commentsList?.empty) lastUserCommented = commentsList?.last()?.authorUser?.displayName Results to: null (no error)

I'm working to get this added but it doesn't make since why the comment strings would cause the description strings to error with unexpected char: '\' since the text is in the description not the comments.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Posted 11 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

34 views 0 5
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