Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Script Runner - Event Listeners - Check if a comment is internal and reporter is part of a group

Hi , 

 

I am trying to create a script listener to get around this : Internal Comments not notifying Agents - https://jira.atlassian.com/browse/JSDSERVER-2418

 

The reason we need this is that we have a team that is on the road most of the day and they would like to keep a track of what happens on their tickets via mail.

 

I have got the first part of the script working where emails are sent to Agents but I need to only fire off the event if the last comment is Internal

import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
     groupManager.isUserInGroup(issue.reporter, 'jira-servicedesk-users')

 

Thanks in advance 

Yas

4 answers

Hi Yaseen,

We have an example in our documentation about checking to see if a comment is internal or not. Could you take a look at it and see if it is of any help?

https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/jira-service-desk.html#_from_an_event_listener

Hi Joshua , 

 

Thank you so much for this, Its the right road.

 

Unfortunately, i am getting this error:

Cannot invoke method getBindings() on null object.

I cant seem to attach the full error but I have provided a screen grab Internal Comments error.JPG

 

 

Thank you so much again.

 

Yas

Hi,

Could you post the exact script you are using in your listener?

Let me see if I understand your use-case:

Problem: Internal comments do not notify agents

Solution:

  1. Create a listener to watch for comments
  2. If the last comment is internal, send an email to the agents. If we the last comment is NOT internal, do not send anything.

Does that sound correct?

Hi Joshua,

 

Absolutely correct - 

  1. Create a listener to watch for comments
  2. If the last comment is internal, send an email to the agents. If we the last comment is NOT internal, do not send anything.

I am using this script :

import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService 
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper
 
final SD_PUBLIC_COMMENT = "sd.public.comment" 
def event = event as IssueEvent
def user = event.getUser()
def comment = event.getComment()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def isInternal = { Comment c -> def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT) .getEntityProperty().getOrNull()

if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
(props['internal'] as String).toBoolean()
}
else { null }
}
if (comment) {
return isInternal(comment) }
return false

Hi,

I have tested the script and it works for me with 100% success. It looks like you have some formatting issues in that script you posted. Is that how the script shows up in your inline script editor? For instance, you have two import statements on the same line in that script.

Could you perhaps try copying and pasting this script and replacing the script you were using?

import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper

final SD_PUBLIC_COMMENT = "sd.public.comment"

def event = event as IssueEvent
def user = event.getUser()
def comment = event.getComment()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()

if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
props['internal'].toBoolean()
}
else {
null
}
}

if (comment) {
log.debug(comment)
return isInternal(comment)
}
return false
Like Ufuk Uysal likes this

Hi Joshua,

 

Its all one script , It was just split for some reason in the post.

 

I am quite sure I am doing something wrong , I have attached a .gif of the steps I take to get there.

 

I cant thank you enough for helping out here.

 

Regards

YasInternal comments Jira.gif

Hi Yas,

After setting up a script listener that sends a custom email, I was able to reproduce this issue. I can see that you will get the "unable to invoke method getBindings()" error.

I think that the error you're receiving has to soley do with the "Preview Issue Key" functionality, not the script itself. I can't quite remember what the issue is with "Preview Issue Key", but I know that it does not work under certain circumstances.

Instead of trying to preview an issue, I would just try to test it on an actual issue. Make an internal comment and see if the listener works. You might edit the listener temporarily to send the email to your address only, so your agents don't get any test emails.

I have tested this script with my own mail server and can see that it does work:

Screen Shot 2017-09-07 at 11.35.12 AM.pngI also see in your picture that you have changed the script to:

(props['internal'] as String).toBoolean()

I would not bother doing that. It's a waste of processing power to do that casting. 

This will give you a static type checking error in the inline editor, but the script will still work.

props['internal'].toBoolean()

Thanks so much Joshua, I will test this over the weekend.

Hi Joshua,

 

The code worked perfectly.

Thank you so much, you have been really awesome helping to get this done.

 

Kind Regards

Yaya

Hi @Joshua Yamdogo _ Adaptavist 

Great this script works well for me. But one question: is there a way to ignore a comment when it has a pasted image?

Hi guys.

I ran into similar problem with one of my customer. Basically we got this problem https://jira.atlassian.com/browse/JSDSERVER-3410 and we are trying to prepare few PoC how to solve it.

One of them is disabled notification scheme + custom listener, which will trigger a notifications for:

  • Agent
  • Customer
  • Related users

And also will be capable to:

  • Distinguish between Internal and Public comment and behave appropriately

We were able to implement above mentioned code, but struggling with last point. Anyone could help with listener? Will give you credential recognition in article I will publish afterward. :-D 

hi @Joshua Yamdogo _ Adaptavist ,

Nice script for internal comments, many thanks. How can we change this script to Reporter?

 

 

 

import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper

final SD_PUBLIC_COMMENT = "sd.public.comment"

def event = event as IssueEvent
def user = event.getUser()
def comment = event.getComment()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()

if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
props['internal'].toBoolean()
}
else {
null
}
}

if (comment) {
log.debug(comment)
return isInternal(comment)
}
return false
Tomáš Vrabec Community Leader Aug 13, 2020

What do you mean by "change to Reporter"? What you are expecting to be done by script? Maybe I can help, but have no idea what you are asking for. 

@Tomáš Vrabec 

I am creating a clone of the record opened by the customer via the service desk into a different project.
If the customer comments on the clone I created, I want to send a warning e-mail to the assigned person via scriptrunner.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - April 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

317 views 3 20
Read article

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