create ServiceDesk internal comment in scriptrunner is not working

Amro Hassaan
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.
April 18, 2017

This sample code to create internal comment from Adaptavist scriptrunner sample defaults to creating external comment, which is not correct

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.json.JSONObject

final SD_PUBLIC_COMMENT = "sd.public.comment"

def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": true])]
commentManager.create(issue, user, "my internal comment", null, null, new Date(), properties, true)

Can someone from Adaptavist help me know why this is happening?

1 answer

0 votes
Jonny Carter
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.
April 20, 2017

May I ask what version of JIRA & Service Desk you're using?

That sample code is consistent with our docs. Could you run the following script (change KEY-1 to a representative issue) in the Script Console and provide the log output?

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 issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def commentManager = ComponentAccessor.commentManager
def issue = issueService.getIssue(user, "KEY-1").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'].toBoolean()
    }
    else {
        null
    }
}

commentManager.getComments(issue).each{
    log.warn("Comment on issue ${issue.key}, id: ${it.id}, internal: ${isInternal(it)}")
}

You can elaborate those logs if more info would help provide context.

Amro Hassaan
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.
April 20, 2017

Jonny, thank you.

logs:

 

2017-04-20 21:48:27,668 WARN [runner.ScriptRunnerImpl]: Comment on issue CTT-53, id: 37958, internal: false
2017-04-20 21:48:27,669 WARN [runner.ScriptRunnerImpl]: Comment on issue CTT-53, id: 39108, internal: true
2017-04-20 21:48:27,670 WARN [runner.ScriptRunnerImpl]: Comment on issue CTT-53, id: 39109, internal: false
2017-04-20 21:48:27,671 WARN [runner.ScriptRunnerImpl]: Comment on issue CTT-53, id: 39111, internal: false
2017-04-20 21:48:27,672 WARN [runner.ScriptRunnerImpl]: Comment on issue CTT-53, id: 39113, internal: true
2017-04-20 21:48:27,672 WARN [runner.ScriptRunnerImpl]: Comment on issue CTT-53, id: 39115, internal: false
2017-04-20 21:48:27,673 WARN [runner.ScriptRunnerImpl]: Comment on issue CTT-53, id: 39117, internal: false

 

Now worth explaining what i am doing. I am propagating comments created on other linked issues to this Service Desk issue and i was expecting them to get created as private but they don't.

As you see the last comment in the logs (id: 39117) was created in the source issue but propagated here as not internal.

 

Amro Hassaan
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.
April 20, 2017

JIRA version: 7.3.0

Scriptrunner: 4.3.19

Amro Hassaan
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.
April 24, 2017

Hi Jonny,

Any thing from the logs i pasted above? I tried all possible tests but still this is not created as internal comment!

Amro Hassaan
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.
April 26, 2017

You guys keep saying on Adaptavist wiki, ask your questions in the atlassian community, ask the question in the altlassian community and here we are. No one came back with any help so far and it has been like 2 weeks or more since i asked this question.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events