Using examples from the Scriptrunner site I have the following code, it runs just fine but the comments are still not showing up on the Portal.
We need to be able to do this otherwise Service Desk is useless for collaborative work within our company. As is, Agents will have to Copy collaborator comments and re-add them as new comments just to make them show up or programatically do it, either way you end up with duplication which is pointless.
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.util.json.JSONObject
import groovy.json.JsonSlurper
import org.apache.log4j.Logger
import org.apache.log4j.Level
final SD_PUBLIC_COMMENT = "sd.public.comment"
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def commentManager = ComponentAccessor.getCommentManager()
def event = event as IssueEvent
def user = event.getUser()
def projectRole = projectRoleManager.getProjectRole('Service Desk Collaborators')
if (projectRoleManager.isUserInProjectRole(user,projectRole,event.issue.getProjectObject())) {
def comment = event.getComment()
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
}
}
def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def originalUser = event.getUser()
try {
def userManager = ComponentAccessor.getUserManager()
def curAssignee = event.issue.getAssignee()
def agentUser = curAssignee
log.info "Assignee - ${curAssignee}"
log.info "original user - ${originalUser}"
jiraAuthenticationContext.setLoggedInUser(agentUser)
if (comment && isInternal(comment)) {
def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": false])]
commentManager.update(comment, properties, true)
}
} finally {
jiraAuthenticationContext.setLoggedInUser(originalUser)
}
}