Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to Post Last Comment via Slack

Tito Vilchez May 23, 2020

Hi everyone:

 

I need to send a notification via slack when a comment is created for an issue. 

I was able to send a message using Scriptrunner Listener "Post a message to Slack".

However, I can't send comment that has been created as part of the message.

My Code is:

 

<% out << currentUser?.displayName %> comentó en el ticket

https://mda.neora.com.pe/browse/${issue.key}
${issue.key}: ${issue.summary}

 

This works fine, but when I added the next code:

 

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

 

I got an error. Log shows:

 

groovy.lang.MissingPropertyException: No such property: lastComment for class: groovy.lang.Binding
2020-05-23 01:47:23,924 http-nio-8091-exec-17 ERROR oscar.diaz 107x2234272x1 2etzel 190.234.91.39,127.0.0.1 /rest/api/2/issue/CRO-145/comment [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, script: com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.PostMessageToChatService
2020-05-23 01:47:23,924 http-nio-8091-exec-17 ERROR oscar.diaz 107x2234272x1 2etzel 190.234.91.39,127.0.0.1 /rest/api/2/issue/CRO-145/comment [c.o.scriptrunner.runner.AbstractScriptListener]

 

I also have tried with:

 

<% if (mostRecentComment)
out << mostRecentComment
%>

 

But get the same error, the only difference is this part:

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

 

I spent the last 24 hours trying to figure out how send comment via slack when a comment is created for an issue. Something that seems to be so basic, but I can't make it to work.

 

Please, your kindly help.

 

Thanks in advance,

 

 

Tito.

 

 

 

 

 

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 23, 2020

The Binding is the context that includes all the variables defined for the script.

Adaptavists makes sure some commonly used variable are available. That's how you're able to just use "currentUser".

But there is no such thing in this binding as lastComment or mostRecentComment

But if you are listening for the Issue Commented event, the event variable includes the comment that raised the event.

So you could do something like this (with some additional formatting suggestions and binding manipulation to do more advanced scripting in the condition block and pass the new variable to the template:

2020-05-23 14_30_14-Window.png

Tito Vilchez May 25, 2020

Thanks a lot @Peter-Dave Sheehan 

It works!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.3.1
TAGS
AUG Leaders

Atlassian Community Events