Hello I am using script runner add-on and I have created a script listener to send a custom email when ever there is a comment on an issue.
I only want to send the email if the comment is a public comment (not internal). Below is my email template with an attempt that does not work (getRoleLevelId returns null always):
<html> <body> <% def commentManager = componentManager.getCommentManager() def comments = commentManager.getComments(issue); // if the comment is internal dont print the reporter and request participants if(comments.last().getRoleLevelId() == 10101){ out << "internal comment" } // else print the external customer who may have recieved the comments else { out << "People on the ticket who recieved an email of the comment:<br>" out << "To:<br>" out << "<b>" + issue.getReporterUser().getEmailAddress() + "</b><br>" out << "CCed:<br><b>" def cf = componentManager.getCustomFieldManager().getCustomFieldObjectByName("Request participants") if(cf){ def cfVal = issue.getCustomFieldValue(cf) if(cfVal){ def size = cfVal.size() if(size){ for( int i = 0; i < size; i++) out << cfVal.get(i).getEmailAddress() + "<br>" } } } } %> </b><br> Current Listed Company:<br> <b><% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Company")) %></b><br> <br>Current Listed Location:<br> <b><% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Location")) %></b><br> <br> Link to the ticket:<br> <a href=https://supportdesk.disti.com/browse/${issue.key}>${issue.key}</a><br> <br> <span style="font-size:26px"><b>Latest Comment:</b></span><br> <% if (lastComment) out << lastComment %> <span style="font-size:26px"><b>Prior Comment:</b></span><br> <% if (latestPriorComment) out << latestPriorComment %> <span style="font-size:26px"><b>Description:</b></span><br> <pre>${issue.description}</pre> </body> </html>
How can I tell if the last comment on an issue is internal or not?
Service Desk uses entity properties for whether the comment is internal or not, amongst other things.
This is fortunate as it means we don't need to use the JSD API directly.
So you can use this code to to get whether any or each comment is internal or not:
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.comments.Comment import groovy.json.JsonSlurper final SD_PUBLIC_COMMENT = "sd.public.comment" def commentManager = ComponentAccessor.getCommentManager() def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService) def user = ComponentAccessor.getJiraAuthenticationContext().getUser() // get whether the comment is internal or not, null means no property found, maybe not an SD issue def isInternal = { Comment comment -> def commentProperty = commentPropertyService.getProperty(user, comment.id, SD_PUBLIC_COMMENT).getEntityProperty().getOrNull() if (commentProperty) { def props = new JsonSlurper().parseText(commentProperty.getValue()) props['internal'] } else { null } } // Examples log.debug "all external comments on ${issue.key}: " + commentManager.getComments(issue).findAll { ! isInternal(it) } commentManager.getComments(issue).each { log.debug("Comment on issue ${issue.key}, id: ${it.id}, internal: ${isInternal(it)}") }
Yes this is for Jira Service Desk. There are comments that can marked as internal which means only JIRA users can see them, not customers, but I do not know how to access the information through scripts. roleLevelId was just a guess at how Jira Service Desk internal comments work, but I dont think that is the correct way. I was expecting roleLevelId to contain information about the if the comment was "internal" or not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'd like to use this solution, but in my implementation ScriptRunner says, that it's unable to resolve the class "com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
".
I think it's because of the experimental API, but every solution i tried failed.
Did anyone has got the same Problem or could help me to solve this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You see that as a type checking error, but it should actually work if you let it execute... There is a known problem with the type checking and certain classes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My script crashes when it tries to execute the following line:
def commentProperty = commentPropertyService.getProperty(user, comment.id, SD_PUBLIC_COMMENT).getEntityProperty().getOrNull()
So it fails when I try to run a method from this class. The error looks like this:
Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> groovy.lang.MissingPropertyException: No such property: commentPropertyService for class: com.custom.Script1543 at com.custom.Script1543.run(Script1543.groovy:77)
JIRA Version: 7.2.1 and ScriptRunner Version 4.3.9. Is it possible that it's not working because we run a test version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jonas, it seems you forgot to import appropriate class and/or instantiate this class:
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService;
...
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService.class)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this is useless - i like to trigger a custom email too, whenever the comment made is NOT internal - however this groovy bogus seems to be way over the top... geeez
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you ever find an answer to this question? I'm trying to figure out the same thing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nope, the closest I got was in the REST API for the JSD, it will return some information on whether a particular comment is marked internal or not. I couldn't figure out a way to get the information in script runner. I guess you could do some kind of parsing from the resulting REST API output inside script runner, but gave up at that point
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got it working here: https://answers.atlassian.com/questions/22654312 Let me know and I'll share the code I'm using for the Condition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's awesome! I was thinking of doing something like that. I'll try it out and mark this as the answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you need to check the comment properties as in my answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what's the condition you have come up with?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if you look at my code below it's not props[internal] - can you paste your full condition? What is the condition for, is the built-in script to send a custom email?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.