Send a custom email with Script listener Error groovy.lang.Binding

Hello,

I have configured a script which is working in version 2.1.17 on JIRA 6.2.5 and it doesnt work in version 4.2.0.2 on JIRA 7.0.4

I hope someone can give me a hint what have changed in new version and how to fix it.

Thanks!


Kind regards,

Sergey

 

Script:

 

<xmp>
<% if (lastComment)
out << lastComment
%>
</xmp>

 

<xmp>
<br>С уважением,
<br><% out << componentManager.commentManager.getComments(issue)?.last()?.authorUser.displayName %> </xmp>

Error:

groovy.lang.MissingPropertyException: No such property: componentManager for class: groovy.lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63) at groovy.lang.Binding.getProperty(Binding.java:105) at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:172) at groovy.lang.Closure.getPropertyTryThese(Closure.java:324) at groovy.lang.Closure.getPropertyDelegateFirst(Closure.java:314) at groovy.lang.Closure.getProperty(Closure.java:299) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:50) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) at groovy.tmp.templates.GStringTemplateScript35$_getTemplate_closure1.doCall(GStringTemplateScript35.groovy:11) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019) at groovy.lang.Closure.call(Closure.java:426) at groovy.lang.Closure$WritableClosure.writeTo(Closure.java:856) at groovy.lang.Closure$WritableClosure.toString(Closure.java:982) at sun.reflect.GeneratedMethodAccessor3277.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$_getDescription_closure15$_closure26$_closure34.doCall(SendCustomEmail.groovy:672) at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$_getDescription_closure15$_closure26$_closure34.doCall(SendCustomEmail.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019) at groovy.lang.Closure.call(Closure.java:426) at groovy.lang.Closure.call(Closure.java:420)



 

3 answers

This widget could not be displayed.

Use ComponentAccessor... there is information on the changes you will need here: https://scriptrunner.adaptavist.com/latest/jira/releases/release-4.1.4.html

You will probably need to use the fully-qualified class name.

This widget could not be displayed.

Hello Jamie,

Thank you for you answer, I missed it sorry for that.

I am not sure that understood you well, I changed next:

<% out << componentManager.commentManager.getComments(issue)?.last()?.authorUser.displayName %> 

to:

<<% out << com.atlassian.jira.component.ComponentAccessor.getComments(issue)?.last()?.authorUser.displayName %> </xmp>

 

In this case I got an error:

No signature of method:com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.tr() is applicable for argument types: (com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$_getDescription_closure15$_closure26) values: [com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$_getDescription_closure15$_closure26@14f6db6b] Possible solutions: is(java.lang.Object), any(), grep(), with(groovy.lang.Closure), grep(java.lang.Object), any(groovy.lang.Closure)

 

Am I on the right way?

Thanks

This widget could not be displayed.

Hi Sergey,

The getCommentManager was missing, therefore with the changes Jamie proposed the template should be

&lt;xmp&gt;
&lt;% if (lastComment)
	out &lt;&lt; lastComment
%&gt;
&lt;/xmp&gt;
 
&lt;xmp&gt;
	&lt;br&gt;С уважением, 
	&lt;br&gt;&lt;%  
    def commentList = com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue)
    	if (commentList)
    		out &lt;&lt; commentList.last()?.authorUser.displayName 
   	%&gt; 
&lt;/xmp&gt;

Also you have to check if there are comments because even if you use the '?' operator you will still get a Cannot access last() element from an empty List

Kind regards

Thanos

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday 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...

306 views 1 4
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