Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Comment Post Function, Sent by the Project Lead

Gavin Minnis December 19, 2018

I am using the following script in a ScriptRunner Post Function to automatically add a comment on transition:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def wertreporter = issue.reporter.displayName

def reporter = "Hello *" + wertreporter + "*,\nThis is an auto-generated comment."

CommentManager commentMgr = ComponentAccessor.getCommentManager()

commentMgr.create(issue, currentUser, reporter, true)

How can I control who creates the comment? Right now, it appears to me that the person who transitions the issue is the "currentUser" and thus creates the comment. (BTW, in case it matters, this transition occurs from a Service Desk approval step.) I prefer that the comment be made by the Project Lead or some other user that I can define.

Any help would be greatly appreciated.

1 answer

1 accepted

0 votes
Answer accepted
Carmen Creswell [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.
December 19, 2018

Hey Gavin! 

You should be able to use this modified version of your code to achieve your goal. This gets the project lead instead of the currentUser. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager

def myProject = issue.getProjectObject()

def projectLead = myProject.getProjectLead()
def wertreporter = issue.reporter.displayName

def reporter = "Hello *" + wertreporter + "*,\nThis is an auto-generated comment."

CommentManager commentMgr = ComponentAccessor.getCommentManager()
commentMgr.create(issue, projectLead, reporter, true)
Gavin Minnis December 20, 2018

Carmen, thank you! That worked perfectly.

Suggest an answer

Log in or Sign up to answer