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:
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!
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> <imports> 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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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) } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.