Hello,
I've been using Built-in script "Custom Email" for scriptrunner.
Command I've used:
if (lastComment)
out << "New Comment:" << lastComment
%>
And it sends out all comments (internal and public) as a emails.
is it possible to show only public comments in custom email body?
Should be possible :) The script below works for an event listener and is straight from Scriptrunners documentation.
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']
}
else {
null
}
}
if (comment) {
return isInternal(comment)
}
return false
You can read more here: https://scriptrunner.adaptavist.com/4.2.0.7/jira/recipes/misc/jira-service-desk.html
Hope it helps! :)
Thanks @Mathis Hellensberg it helped :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I glad it did! Thanks for the high five :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is probably not the most optimal way to do it but in case anyone else finds this thread like I did, this is how I accomplished it in my DC instance. This uses the 'Send a custom email' ScriptRunner post-function and the script is placed within the 'Condition and Configuration' section. It uses a modified version of what was supplied above by Mathis!
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
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserManager
final SD_PUBLIC_COMMENT = "sd.public.comment"
def user = ComponentAccessor.getUserManager().getUserByName("automationbot") //grabs service account to pull list of comments
def allComments = ComponentAccessor.getCommentManager().getComments(issue) //grabs all comments from the trigger issue
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
}
} //function created by Adaptavist
List extArray = [] //defines array to hold external comments
if(allComments){ //If a comment exists enter this statement
allComments.each{ comment -> //sort through each comment
if(!isInternal(comment)){ //if the comment is external i.e. NOT internal
extArray.add(comment.body) //add the comment body to the extArray
}
}
if(extArray){ //if the extArray isn't empty pass variable 'CommentPassed' to templates
config.CommentPassed = extArray.last() //passes the last external comment i.e. most recent
}
else{ //if the extArray doesn't exist all comments are internal
config.CommentPassed = "No comment to display"
}
}
else{ //Case for no comments on the issue
config.CommentPassed = "No comment to display"
}
NOTE: Account used to sort the comments MUST have browse project permission to view comment properties. Otherwise the comments may not be sorted as expected. Found in the cloud API documentation https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-comment-properties/ but I assume it's the same for DC and Server.
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.