Comment Visibility Internal Comments

I've created a scripted field and create a groovy script (Script Runner). I've got an error on lane 10 (def event = event as IssueEvent). Error: The variable (event) is undeclared.

What schould I do?

 

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

2 answers

This widget could not be displayed.

Hi Thanos

I'd like to create a scripted field that used the CommentService and CommentPropertyService to determine whether the most last comment was public or private.

This widget could not be displayed.

Pascal, 

Try something like 

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

final SD_PUBLIC_COMMENT = "sd.public.comment"

Issue issue = issue

def commentManager = ComponentAccessor.getCommentManager()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def lastComment = commentManager.getLastComment(issue)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

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
    }
}

lastComment ? isInternal(lastComment) : null

PS. This is only for comments in a Service Desk issue. For JIRA issues the visibility of a comment depends on group or role levels. 

regards Thanos

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

576 views 25 15
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you