Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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?

2 answers

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! :)

Do you know how to do this with Jira and scriptrunner cloud?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

173 views 2 8
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you