Add new comment with new field value when field is updated

Alex Christensen Community Champion Nov 05, 2015

We have a need to know when a value of a particular field is changed. Yes, this information is stored in an issue's History tab, but the information that is stored in the History tab is pretty dense and not easy to wade through when trying to find information quickly (which is the problem Sean outlined here).

Ideally, what I'd like to do is have JIRA automatically add a new comment with the field's new value along with the date that change occurred. However, the only way I've found to do this is via a groovy script in a post-function - that's great, but I want to be able to add a comment even if this field is changed in the issue's Edit screen or changed inline when viewing an issue.

After some research, I can see two options:

  • Use this workaround - the only thing I don't like about this is that the user has to remember to change the field using this "transition" instead of editing the field inline or in the Edit screen. Not very user-friendly, in my opinion.
  • Create a custom listener that listens for events that trigger when a field is updated and check if that field is updated, then add a comment to that issue. However, this is a bit outside of our skillset and we do not have the resources to create this functionality for a requirement with this smaller size of scope.

Is there a plugin that might allow us to do this easily, or a better option than what I've already listed above? Thanks in advance for your time and help!

1 answer

1 accepted

This widget could not be displayed.

if you can write a groovy script post function to do this, writing a groovy listener is not a whole lot harder.  This assumes you have ScriptRunner installed.  an oversimplification would be something like this (needs work and testing but this should get you going!

package com.<your class name here>
public class <ListenerName> extends AbstractIssueEventListener
    private final EventPublisher eventPublisher;
    public FieldListner(EventPublisher eventPublisher) {this.eventPublisher = eventPublisher; }
    public void issueUpdated(IssueEvent event)
    {    CommentManager commentManager = ComponentAccessor.getCommentManager();
         List changeItems = issueEvent.getChangeLog()?.getRelated("ChildChangeItem");
        for (GenericValue changeItem : changeItems)
        {   String thisField = changeItem.get("field").toString();
            if (thisField.equalsIgnoreCase("YOUR FIELD NAME HERE") 
            {    commentManager.create(issue,issueEvent.getUser().getName(),changeItem.get("oldstring").toString(),false)}


If you want to fire it on transitions as well you need to add the event types..

 public void issueUpdated(IssueEvent event)  and change isseUpdated to what ever the event type is that is fired on that transition.
Alex Christensen Community Champion Nov 05, 2015

Hi, Jeff - thanks so much for this! This should prove to be helpful. We do have ScriptRunner installed. I completely looked over the fact that we can create scripted listeners instead of creating custom listeners and uploading the custom code like you would a plugin. So, I'll give that a shot - thanks!

Alex Christensen Community Champion Dec 07, 2015

With Jeff's help, I was able to get this working. Here's my final code that I used in case anyone else has a similar requirement for their system. import com.atlassian.jira.component.ComponentAccessor def commentManager = ComponentAccessor.getCommentManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def user = ComponentAccessor.getJiraAuthenticationContext().getUser() def completedMigrations = customFieldManager.getCustomFieldObjectByName("Completed Migrations") def values = issue.getCustomFieldValue(completedMigrations) def today = new java.sql.Timestamp(new Date().getTime()) def changeItems = event.getChangeLog()?.getRelated("ChildChangeItem") for (def changeItem : changeItems) { if (changeItem.get("field").toString().equalsIgnoreCase("Completed Migrations")) { commentManager.create( issue, user, "Completed Migrations as of " + today.format("yyyy-MM-dd") + ": " + values, false) } }

Suggest an answer

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

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

83 views 0 1
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