How to add fixed text in comment on transition using Script runner post function

I would like to add fixed text to user comment..For example when user press "cancel" button (on transition in workflow), i would like to run custom script runnner code that is going to add prefix - word "Cancel" - before the user comment.

When user cliked on Cancel - custom screen opened with requirmenet to enter reason for cancel, and comment...

Code that i am using is:

import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
commentManager.create(
issue,
user,
"CANCELLED",
false)

 

But the problem is that on transition  i now have two lines in comments:

xxxxx yyyyyyy added a comment - 5 minutes ago

CANCELLED

 

xxxxx yyyyyy  added a comment - 5 minutes ago

We decided to cancel issue

 

I would like to have just one line:

xxxxx yyyyyy  added a comment - 5 minutes ago

CANCELLED - We decided to cancel issue

 

 

 

1 answer

I tried this code that works similar

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

Issue issue = issue
// Get the comment, the user added in the form
def originalComment = transientVars.comment as String
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

// Concat to the original comment, ours. Use \n for a new line
def comment = "-CANCELLED-" + originalComment
commentManager.create(issue, user, comment, true)




 

But i am getting also two lines in comment - one with customer entered text, and other with prefix
-CANCELLED-

xxxxx yyyyyyy added a comment - 5 minutes ago

We decided to cancel issue

 

xxxxx yyyyyy  added a comment - 5 minutes ago

-CANCELED- We decided to cancel issue

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 ...

3,105 views 13 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
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