Add comment as defined user

Cary Watkins November 15, 2017

I want to post comments on fast track transitions. I would like the comments to show as added by the system as opposed to the submitter/creator.

Can a comment be added but also define the user creating the comment as well?

2 answers

1 accepted

0 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
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.
November 16, 2017

Hi Cary,

Yes, I believe this should be possible. The CommentManager has several different methods for creating a comment. 

Comment create(Issue issue,
               ApplicationUser author,
               String body,
               String groupLevel,
               Long roleLevelId,
               boolean dispatchEvent)

It allows you to specify the issue, the author, the text of the comment, and a bunch of other things.

Cary Watkins November 24, 2017

HI Joshua - Thank you for the response.

I found the same and did try it out. Below is what I ended up with. I think what I am struggling most with is application of these functions I field; my own lack of technical knowledge. Can you fill in the gaps to what I am doing wrong? I think I defined the issue properly, but how do I define the author properly?

 

Ultimately I wont all comments like this added as a generic user. User's full Name is "Service Desk Assistant", ID is SD.Assist.

def issue = event.issue

Comment create(issue,author,"This ticket automatically approved due to the permissions of the submitter.", true)
0 votes
Cary Watkins November 27, 2017

Hi Joshua,

 

I think I may have made the necessary modifications in order to make this work. If you could review the below and possibly provide any best practices, or point out any unnecessary steps, this would be greatly appreciated!

 

New Action:

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()
def issue = event.issue
def userManager = ComponentAccessor.getUserManager()
String UserName = "SD.Assist"
def user = userManager.getUserByName(UserName)
String CommentText = "Comment to be applied."

commentManager.create(issue,user,CommentText,true)
Joshua Yamdogo @ Adaptavist
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.
November 27, 2017

Hi Cary,

Great work! That script looks like it should work fine in a listener. The only thing you might look into changing is using getUserByKey() instead of getUserByName(). Getting a user by their key will make sure you always have the correct user, because user keys are unique. More than one user can have the same username, as they are not unique. I seriously doubt this will make a difference in your case, but just thought I'd let you know.

Have you tested the script out yet? Seems to be working in my instance:

Screen Shot 2017-11-27 at 2.36.58 PM.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events