How to get Comment from screen on transition using groovy script

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

1 answer

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.

 

hey Thank you so much. It works.

actually my post function position was wrong

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,966 views 12 18
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