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

1 accepted

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 Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

772 views 2 19
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