How to get Comment from screen on transition using groovy script

Prashant Mali June 8, 2017

I want to copy comment from one issue to linked issue only when I add comment on screen at the time of resolving first issue. I am using custom post script.

 

Can you please help .how to use groovy for that

4 answers

1 accepted

3 votes
Answer accepted
Thomas Venekamp June 8, 2017

Hello,

we add some phrases to comments written during a transition in our workflows. Our biggest problem was to get the information if a comment has been written on the transition screen. With the following code you can get the information you need.

 

import com.atlassian.jira.component.ComponentAccessor

// Manager
def cm = ComponentAccessor.getCommentManager()

currComments = cm.getComments(issue)

if (!currComments.isEmpty()) {
 currComment = currComments.get(currComments.size()-1)
 if (issue.getUpdated() <= currComment.getUpdated()) {
  log.debug "There is a comment during transition."
 } else {
  log.debug "There is no comment during transition."
 }
}

I hope this helps to solve your problem. Now you can add something to the comment or use it for whatever you like.

EDIT: I missed an important information for my answer.

You have to put this code in the post-function section of your workflow transition after the step "Add a comment to an issue if one is entered during a transition."
If you just add this code, it will be added on top and then you have to move it below the step. You can't access the new comment earlier.

 

Prashant Mali June 8, 2017

hey Thank you so much. It works.

actually my post function position was wrong

Jorge Jerez December 1, 2019

Is there any way to edit the comment was made in that screen? 

Vladislav December 2, 2019

Hi Jorge,

The comment that was made on transition will appear under regular comment section in the JIRA issue.

If you have 'Edit Comments' permissions on Permission scheme then you would be able to edit comments.

Regards,

Vlad

Jorge Jerez December 2, 2019

Hi

 

Sorry, my questions wasn't what I wanted to know. I mean how I can edit that comment during the transitions using Script Runner. 

Vladislav December 3, 2019

Hi Jorge,

There are only two options to edit a comment:

1) During transition, that means on the screen of current transition.

2) When comment already submitted and appears under regular comments section.

Did I get you right?

 

Regards,

Vlad

6 votes
Evgeniy_Russkikh February 15, 2019

There is much easier way to get comment from transition screen:

transientVars.get("comment")

Vladislav October 9, 2019

As of today 2019-OCT-09 it works fine as well with JIRA 8 and scriprunner v5.

1 vote
Vladislav August 19, 2020

Hi Marina,

Did you see answer from Evgeniy_Russkikh above:

There is much easier way to get comment from transition screen:

transientVars.get("comment")

0 votes
Marina Veselić July 15, 2020

An interesting question that I would like to know the answer to. :) I know how to get the last comment, but it isn't always the one entered on the transition.

Suggest an answer

Log in or Sign up to answer