It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to Post Last Comment via Slack

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

0 votes
Answer accepted

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.3.1
TAGS
Community showcase
Posted in Jira Service Desk

How has Jira Service Desk increased productivity in your org?

Hi Jira Service Desk community, Atlassian is on a mission to unleash the potential of all teams, and we know that tools are just one piece of that puzzle. With Jira Service Desk, we have productiv...

187 views 0 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you