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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


Creating comments on servicedesk portal with scriptrunner


Hello! I'm trying to create comment on servicedesk portal with scriptrunner via workflow postfunction. Problem is that this comment don't become visible on Service Desk portal, and visible only on "browse issue" screen. Can anybody help ? 


 Here is code:


import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.json.JSONObject

String messageToAdd = "We got your request and will answer you ASAP";

final SD_PUBLIC_COMMENT = "sd.public.comment";
def properties = [(SD_PUBLIC_COMMENT): (new JSONObject(["internal": false] as Map))];

ApplicationUser johnGalt = ComponentAccessor.getUserManager().getUserByName("jhon.galt");
log.warn("Getted user is " + johnGalt.getName());

ComponentAccessor.getCommentManager().create(issue, johnGalt, messageToAdd, true);

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Cristian Rosas [Tecnofor]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Nov 20, 2018

This has been extracted from Adaptavist documentation, modified it a little and tested in the Script Console and it works:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.json.JSONObject

final SD_PUBLIC_COMMENT = "sd.public.comment"

def commentManager = ComponentAccessor.getCommentManager()
def issueManager = ComponentAccessor.getIssueManager()

def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": false])]
commentManager.create(issue, user, "mi comentario", null, null, new Date(), properties, true)


@Cristian Rosas [Tecnofor] It is works from script console. Also it works from postfunction, when you manually press on transition button. 

But when you attach this postfunction to automatically passing workflow step ( for example on "create issue transition" or to some step that passes automaticaly wirh scriptrunner on some conditions) it creates internal comment, that is not visible on servicedesk script. 

@Evgeniy Buturlia This is because possibly the user who creates the comment is not an agent, that is, a user of the service-desk-agents group.
I tried the following script and it worked in a "create issue transition":

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.json.JSONObject

final SD_PUBLIC_COMMENT = "sd.public.comment"

def issueKey = issue
def userManager = ComponentAccessor.getUserManager()
def CurrentUser = userManager.getUserByName("sysbot") as ApplicationUser // Test user, sd-agent
CommentManager commentManager = ComponentAccessor.getCommentManager()
def comment = "My external comment." // Comment

def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": false] as Map)]
commentManager.create(issueKey, CurrentUser,comment, null, null, new Date(), properties, true)

@Jose Carlos Nieto 

This will now work, because when script runs from a non-servicedesk agent user, it can'not add comment with visibility level "public", even if comment user is servcedesk agent. 

To make it work you need add this code before  "commentManager.create(...)":



Where "sysbot" is user with servicedesk agent permission. 

@Evgeniy Buturlia i try and doesn't work. But i changed last argument of method to "false" and script add public comment.


commentManager.create(issueKey, CurrentUser,comment, false)


I wonder if this is correct

Comment manager creates comment from CommentUser BUT it run's from current loggined in user. If current user can not post puclic comments, it will not be able to create public comment. 


Last argument is responcible for dispatching event. You may read about it here :

AUG Leaders

Atlassian Community Events