Auto-Comment with Script Runner Grovvy Script

hello everybody,

i want to generate a comment over script runner and a groovy script when executing a transition. 

that is the script. i want to read the value in the reporter-field

import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.*;
import com.atlassian.jira.issue.fields.DefaultFieldManager;

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

reporter = ""+issue.getFieldValue( ComponentAccessor.getFieldManager().getFieldObjectByName("Reporter")).displayName
wertreporter = issue.getFieldValue(reporter)

reporter = "Hallo *" + wertreporter + "*, \
\n\ndein Notebook wird vorbereitet.\
\nTechnical Services"

CommentManager commentMgr = ComponentAccessor.getCommentManager()
commentMgr = (CommentManager) ComponentAccessor.getComponentOfType(CommentManager.class)

//Der wirkliche Kommentar
commentMgr.create(issue, currentUser, reporter, true)

this is the error:

Time (on server): Wed May 24 2017 13:13:53 GMT+0200 (W. Europe Daylight Time)
The following log information was produced by this execution. Use statements"...") to record logging information.
2017-05-24 13:13:53,894 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-05-24 13:13:53,894 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITSD-161, actionId: 61, file: /data/jira/home/groovy/ts-jsd-notebook-change-deployment.groovy
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.DefaultFieldManager.getFieldObjectByName() is applicable for argument types: (java.lang.String) values: [Reporter]

can somebody help?


1 answer

1 accepted

Hey Toni,

I've taken your script and cleaned it up a little bit for you. I tested it myself and didn't get any kind of error:

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 =

def reporter = "Hallo *" + wertreporter + "*, \n dein Notebook wird vorbereitet.\n Grüsse \n Technical Services"

CommentManager commentMgr = ComponentAccessor.getCommentManager()

//Der wirkliche Kommentar
commentMgr.create(issue, currentUser, reporter, true)

I think this should do what you are wanting. Here are some detailed steps over how to use this script in a post function:

Steps to use in transition:

  • Go to the workflow of the project that you would like this functionality to be present in.
  • Edit the workflow in Diagram view.
  • Click on the transition that you would like to add it to.
  • Choose Post-Function in the pop-up that appears to the right of the screen.
  • Choose to add a new Post-Function and then select "Script Post-Function" and hit "Add."
  • Then choose a "Custom Script Post-Function."
  • You then add the code, or something similar, in the Inline Script box (add a relivent note).
  • After you add the Post-Function, ensure that it is the very last script ran by pushing it down to the very bottom of the diolog box that reads "The following will be processed after the transition occurs."

You may then publish the workflow and you're good to go.

Hello Aidan,

i know how to edit and publish a workflow :->

My Problem was that i want to print the displayname of the reporter over the grrovy script.


Anyway thank you it works fine.


Best regrads


Hello Aidan,

how can i print the displayname and not the username?


Hallo test,

dein Notebook wird vorbereitet.

Technical Services



def wertreporter = issue.reporter.displayName

Can you please help me how to print a custom message with approver or rejector name. For ex: if the issue is in waiting for approval, once it is approved i would like to display a comment as "approved by name of the approver "

Any help will be greatly appreciated as it is very urgent.

Can anybody helpme?

are you working with jira-service-desk?

Yes, working with jira-service-desk

@Srinivas Adepu It depends on how your approval process works, but assuming that the issue will be approved when the approver transitions the issue, you can set up a Script Post-Function that contains code to create a comment like this:

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.commentManager
commentManager.create(issue, currentUser, "This is a new comment by ${}", false)

Both the variables "issue" and currentUser will be available to you when creating a Custom Script Post-Function. 

Let me know if that'll work for you! :D


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

442 views 0 9
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