Add comment as defined user

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

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.

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)

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)

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

177 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you