It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Add comment to _current transition_ in Jira post function?

I want to add a comment (always the same string) in a post function - and I want to add it in the same transition, as if it were entered in the "Comment" field in the transition screen, not firing a separate event. In particular, I want the comment to appear in the notification mail (the same notification mail as the rest of the update). Is this possible? 

I can add a comment as a separate event, with, for example, JIRA Misc Workflow Extensions or ScriptRunner, but then the users would get a separate mail about the comment (or no mail about the comment at all), and I want the update and the comment to go together. I am thinking ScriptRunner might be able to do what I want, but I haven't found any examples. 

(I tried to let the user add a comment in the transition instead, using a screen which doesn't contain any fields. That works nicely when doing the transition on one issue, but when bulk transitioning issues, I do not get to fill in the comment, since the screen doesn't contain any fields. Thus I'd really appreciate any pointers on how to add a comment to the current transition, or be told it's not possible.)

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough Community Leader Jan 13, 2017

I guess when you mention "add a comment as a separate event" with Script Runner, you're not working in the post function?

I couldn't find any examples on the web at a glance either, but my notes say that this code should work in a post-function


import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager


def CommentManager commentManager = (CommentManager) ComponentAccessor.getCommentManager();

def commentToMake = "I see penguins"
commentManager.create(issue, transientVars.context.caller, commentToMake, false)

It's a little bit old though, for version 5.  The main thing in it is the pointer to comentManager which should still do the job. 

There's two little caveats:

  1. you'll find that if you have a transition screen and the user makes a comment, you'll get two comments going in...
  2. You need to be careful where to place it in the order of post-functions, or it vanishes

Thanks! I've been down that road before, but it's good to know it's actually the right road. 

However, the issue does get the comment added, no separate event fired - but still, I see no penguins in the notification mail. (The $comments variable is not set, says Velocity; I haven't looked deeper, and don't know if I could.)

Then again, since I don't necessarily need to tell users about anything except the comment (even if it would be nice), I could actually make the whole transition fire an event sending no mail at all, and then let the comment creation send its mail instead. It's not a nice workaround, but it's beginning to look as if that'll have to do.


Thanks again for your time! (And for all the other questions you've answered previously, where all I needed to do was google. smile ) 

Nic Brough Community Leader Jan 16, 2017

Ok, there shouldn't be an extra event fired - that's done by a post function after the other post-functions.  I thought that should have included the additional comment, it seemed to on v5.  Mind you, with script-runner, you can send an additional email anyway, and that can definitely include the comment.

Could you check the order of the post-functions, making sure your comment is before all the "index" and "write stuff", and that the event firing is after it?

I do comment - store - reindex - fire event, in that order, and it seems like the comment is added "on the side" but with the "Issue Commented" event prevented, rather than adding the comment in the whole transition. 

I'm currently using JETI for one set of mails sent, and standard notifications for another set, so I don't think it would be a good idea to create mail with Script Runner as well; that'd be a bit too messy. (And it would have to be everything in the same mail, still - additional emails is no problem, but that would be confusing and irritating in this case.)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

We want to hear from you! How do you use Slack and Atlassian together?

Hi Everyone! My name is Mina and I am on Atlassian’s Ecosystems Marketing team. Our team is focused on our technology partnerships and marketplace apps. One of Atlassian’s partners is Slack, who ...

74 views 0 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you