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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,456,273
Community Members
 
Community Events
176
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

Atlassian Community Events