create ServiceDesk internal comment in scriptrunner is not working Edited

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

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.

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.

 

JIRA version: 7.3.0

Scriptrunner: 4.3.19

Hi Jonny,

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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

268 views 0 6
Read article

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