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 new comment with new field value when field is updated

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

3 votes
Answer accepted

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.

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!

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 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

948 views 7 0
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