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

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

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
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

417 views 7 5
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