Example scripts
To homepage
Jira Service Desk

Create a Comment on a Jira Service Desk Ticket in Groovy
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira Service Desk (3.10 - 4.6)

ScriptRunner For Jira (5.6.14)
Language |
groovy
import com.atlassian.jira.bc.issue.comment.CommentService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.servicedesk.api.comment.ServiceDeskCommentService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.servicedesk")
final String issueKey = "TEST-1" // the key of the issue
final String comment = "This is a comment" // the comment you want to add
static void createServiceDeskComment(MutableIssue issueToComment, String text, Boolean internal) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
if (issueToComment.projectObject.projectTypeKey.key == "service_desk") {
def serviceDeskCommentService = ComponentAccessor.getOSGiComponentInstanceOfType(ServiceDeskCommentService)
def createCommentParameters = serviceDeskCommentService.newCreateBuilder()
.author(user)
.body(text)
.issue(issueToComment)
.publicComment(!internal)
.build()
serviceDeskCommentService.createServiceDeskComment(user, createCommentParameters)
} else {
def commentParameters = CommentService.CommentParameters.builder()
.author(user)
.body(text)
.issue(issueToComment)
.build()
def commentService = ComponentAccessor.getComponent(CommentService)
def validationResult = commentService.validateCommentCreate(user, commentParameters)
commentService.create(user, validationResult, true)
}
}
//Example of function in use
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey(issueKey)
createServiceDeskComment(issue, comment, true) //false means public, true means internal
Having an issue with this script?
Report it here