Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Add Comments to Service Desk Linked Issues

Shah Baloch April 21, 2021

Hi, I created a comment listener when a user adds a comment to an issue, the listener adds the same comment to the linked issue. It is working fine with Jira software projects, I tested with two Jira Software projects. However, it's not adding comments to Service Desk linked issue. There is a service desk issue link to the Jira software issue. I want to be able to add comments in Jira software and it should be added to the Service Desk issue too but it's not working with SD. Any idea why it works with Jira software but won't work with Service Desk? What I'm missing?

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.user.ApplicationUser;

CommentManager commentMgr = ComponentAccessor.getCommentManager()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def issue = event.issue
def lastComment = commentMgr.getComments(issue).last().body

def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())

def output = ""
for(l in links) {
output = output + + ": " + l.getDestinationObject() + "<br/>"

commentMgr.create(l.getDestinationObject(), currentUser, lastComment, false)

Thank you for your help.

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Thomas April 22, 2021

Unfortunately, I can't help you with your code, but I have a script like this in my Jira SM project. Maybe it will be useful to you and you can find a solution.


import com.atlassian.servicedesk.api.comment.ServiceDeskCommentService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin


ServiceDeskCommentService serviceDeskCommentService

final SD_PUBLIC_COMMENT = 'sd.public.comment'

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

// check if the comment is a public service desk comment
def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(loggedInUser,, SD_PUBLIC_COMMENT).entityProperty.orNull
commentProperty ? new JsonSlurper().parseText(commentProperty.value)['internal'] : false

//The comment visibility value is true when the comment is internal and false when the comment is public
def commentVisibility = (event.comment) ? isInternal(event.comment) : false

//in this point, you can do anything with this value. For example: Create a new public comment when the created comment is not public
if (commentVisibility) {
def createCommentParameters = serviceDeskCommentService.newCreateBuilder()
.body('I have written a private comment')
serviceDeskCommentService.createServiceDeskComment(loggedInUser, createCommentParameters)
Shah Baloch April 22, 2021

Thank you @Thomas for responding. I copied and pasted your script in the console to test the script, it is not working. I'm getting errors. I'm attaching screenshots. Any idea why?


AUG Leaders

Atlassian Community Events