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
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

471 views 7 5
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