Change an internal comment to external/shared with customer in Service Desk Using scriptrunner

Julian Böhmer April 19, 2017

Hi,

we are using jira software and jira servicedesk on the same server, so we are able to move issues from jsd to software.

Everything works fine, but there is the problem, that in jira servicedesk when creating comments you can choose if it is an internal comment or you want to share the comment with the customer.

Jira software works not like this. in jira software we can select a (internal) group for which the comment is only shown.

when moving now a issue with internal comments from jira servicedesk to jira software project the internal comments are vissible for the customer.

is there a way to fix this?

Thanks

Julian

1 answer

0 votes
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 10, 2017

Hi Julian,

So a script that you could run from your script console and copy an internal comment from a service desk issue (SDP-2) to a jira project one (TAT-1) and make it visible only to jira-administrators will look 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


def commentManager = ComponentAccessor.getCommentManager()
def issueManager = ComponentAccessor.getIssueManager()

def issueFrom = issueManager.getIssueByCurrentKey("SDP-2")
def lastComment = commentManager.getLastComment(issueFrom)

def issueTo = issueManager.getIssueByCurrentKey("TAT-1") as Issue
def isInternalComment = isInternal(lastComment)


if (isInternalComment) {
    commentManager.create(issueTo, lastComment.authorApplicationUser, lastComment.body, "jira-administrators", null, lastComment.created, false)
}

static boolean isInternal (Comment c) {
    final SD_PUBLIC_COMMENT = "sd.public.comment"
    def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
    def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
        .getEntityProperty().getOrNull()

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

    false
}

Of cource you can change it in order to meet your requirements. 

Please let me know if this does the trick and if you have any further questions.

regards, Thanos

Suggest an answer

Log in or Sign up to answer