Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,294,223
Community Members
 
Community Events
165
Community Groups

Add Comments to Service Desk Linked Issues

Edited

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.link.IssueLink;
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.issueLinkType.name + ": " + l.getDestinationObject() + "<br/>"

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

Thank you for your help.

1 answer

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.jira.bc.issue.comment.property.CommentPropertyService
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

@WithPlugin('com.atlassian.servicedesk')

@PluginModule
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, c.id, 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()
.author(loggedInUser)
.body('I have written a private comment')
.issue(event.comment.issue)
.publicComment(true)
.build()
serviceDeskCommentService.createServiceDeskComment(loggedInUser, createCommentParameters)
}

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?

ThanksSD_Comment.JPGSD_Comment2.JPGSD_Comment3.JPG

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

255 views 0 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you