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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JIRA version: 7.3.0
Scriptrunner: 4.3.19
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.