Getting Started

JIRA Extension Points

Behaviours

Recipes

Releases

Here are some limited examples for scripting JIRA Service Desk. Please let us know what you require…​

Getting Comment Visibility Levels.

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.

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

// Example:all external comments on issue
log.debug commentManager.getComments(issue).findAll { ! isInternal(it) }

// iterate comments and check external property
commentManager.getComments(issue).each {
    log.debug("Comment on issue ${issue.key}, id: ${it.id}, internal: ${isInternal(it)}")
}