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.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.