Automatically add a comment

I am using Groovy Scriptrunner. How can I add a comment that says, "In UAT" when a transition is completed for an issue?

1 answer

1 accepted

Hey Karrie!

I've coded up a simple example for you to use here:

import com.atlassian.jira.component.ComponentAccessor

//Get appropriate managers/handlers
def commentManager = ComponentAccessor.getCommentManager()
def authContext = ComponentAccessor.getJiraAuthenticationContext()

//Define currentUser because it is not an available default
def currentUser = authContext.getLoggedInUser()

//Add comment to issue transitioned. The name on the comment will be the current user's name.
//The boolean value delegates whether or not an event is fired.
commentManager.create(issue, currentUser, "This is where the comment goes!", true)

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.

The script that I provided above is a very simple example, but you can add more complex properties to the comment or add make a default user to be the commenter if you like (etc...). You can see other possible methods to use in the JIRA API.

Thank you!! That worked perfectly!

No problem, if you have any other questions let me know! :)

Suggest an answer

Log in or Join to answer
Community showcase
Maarten Cautreels
Posted Thursday in Off-topic

Friday Fun: What's your favourite beer/drink

As a Belgian, beer-lover and home brewer, beer is one of my great passions. I love the fact that with just a few ingredients (usually just water, hop and malt) you can create so many different tastes...

286 views 38 9
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot