JIRA: Automatically add a comment on transition?

Dave Donnelly [Sensata]
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.
August 2, 2011

Any way to automatically add a comment on a workflow transition. I used to use the CJH plugin for this but it seems to have disappeared from the plugin repository. Anything else that will fulfill this functionality?

Background:

We use comment on transition to timing between the first response and the resolution time. First response is calc'd as the time from the first comment so I need a comment to be automatically inserted as the user clicks the workflow transition "start work" for the task.

Any ideas?

Thanks in advance.

2 answers

1 accepted

6 votes
Answer accepted
JamieA
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.
August 2, 2011

It can be done with a simple groovy script placed as a post-function on the Start Progress transition, ie: http://pastebin.com/9S8BisbH

That example uses the user doing the transition to add the comment, you could use another user if you prefer.

Alternately there are probably ten other plugins that could do it too.

(Also see script runner)

Dave Donnelly [Sensata]
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.
August 3, 2011

Thanks for that Jamie. I have zero experience with scripting so not entirely sure how to implement that but I'll give it a go. Thanks again.

JamieA
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.
August 3, 2011

No problem. Take the linked file and put it on a file on your jira server calling it whatever. Install the script runner plugin, edit the workflow, add a post-function, choose "run script", enter the path to the file. Post back if you have any problems...

Dave Donnelly [Sensata]
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.
August 3, 2011

Will do. Thanks a million :)

A November 21, 2013

thanks for the pastebin code. what would be the syntax for adding a comment which would include current assignee name - something like "Approved by Bill Gates"? (Bill Gates was performing a transition...)

Aravindi Amarasinghe April 17, 2019

Hi @JamieA 

Here is my code for adding auto comment. Its working fine and adds comment as the current user. I want to add comment as a particular user. EG: jira.donotreply. I couldn't find a way to do it yet. 

Can you please help me to do that? Thank you!

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager

ComponentManager componentManager = ComponentManager.getInstance()
CommentManager commentManager = componentManager.getCommentManager()

commentManager.create(issue, transientVars.context.caller, "The Auto comment", false)
Rob Horan
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.
July 8, 2020

Hi @Aravindi Amarasinghe 

I am trying to add an automatic comment as well, so I copied and pasted your code, and wound up with multiple errors.  Is part of this missing?

Julien July 17, 2020

Hi @Rob Horan
APIs evolve ... try using ComponentAccessor instead of ComponentManager.

This should better work :

import com.atlassian.jira.component.ComponentAccessor

def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def commentManager = ComponentAccessor.getCommentManager()
def user = jiraAuthenticationContext.getLoggedInUser()

commentManager.create(issue,user,"The Auto comment",false)
1 vote
Johnson Carry September 30, 2020

Hi All I want to automatically add a pre-defined comment to JIRA issue whenever certain transitions are performed in the workflow. Yes, installed the plugin and found a groovy script that worked. 

Suggest an answer

Log in or Sign up to answer