Custom Field Update Listener

Ankit Bhasin April 7, 2014

Hi Everyone,

I am writing a Listener which needs to capture the event(s) when the custom field ("Epic Link" from JIRA AGILE) of the issue is updated.

@EventListener
    public void onIssueEvent(IssueEvent issueEvent) {
    }

I have following questions

  1. When the custom field of an issue is updated, does it fires an event which can be captured inside a listener? If yes, then how?
  2. Can we create a custom event to be fired when the custom field of an issue is updated? If yes, then how?

Please advice me if we can take any of the the above approach or if there is a better way to capture the custom field update event.

Thanks in advance.

Cheers,

Ankit

1 answer

2 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2014

1. Yes, an event is fired on every occaision a field is changed, but you'll need to trap several

2. No. Events are fired by things that happen to issues, not fields

2 is the whole point of events, they are issue changes. A field could be changed on create issue (from null to something), issue edit, during a transition, and some can change as a result of other actions.

Different actions on issues fire different events, but they may well have similar field changes.

So, what you need to do is write a listener that will catch most events that might contain a field update, and then read the contet of the change to see if the field has changed (then if it has, do your logic)

Ankit Bhasin April 7, 2014

Hi Nic,

Thank you for quick response. I am not sure how to "write a listener that will catch most events".

If I change my listener code to the following will it be able to capture most of the events?

If not then will you be able to provide me with some code example.

@EventListener
public void onIssueEvent(AbstractEvent abstractEvent) {
}

Thanks,

Ankit

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2014
That will capture all events. You might want to code it to ignore some Events, rather than run code that looks for a change of your field every time, but you don't really have to. As an example, I would consider ignoring issue delete, comment update and delete, and so on. Events where your field cannot change...
Ankit Bhasin April 7, 2014

Hi Nic,

I changed my listener to following to test that I am able to capture the event fired when the custom field("Epic Link" from JIRA AGILE) is changed.

@EventListener
public void onEvent(AbstractEvent event) {
}

But I am not able to catch the event fired on change of custom field value. Though I am able to catch the event when the non-custom fields are updated. I think I am missing something obvious.

Thanks,

Ankit

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2014

Again, events are fired by ISSUE changes. When you change a field, that's an issue updated or one of the transition events.

When you change the ISSUE, events are fired. You need to catch them

Ankit Bhasin April 8, 2014

Hi Nic,

As per your comment

Again, events are fired by ISSUE changes. When you change a field, that's an issue updated or one of the transition events.

Let say event X is fired when a custom field for an issue is changed.

Event X can be

  1. issue updated event
  2. transition event
  3. some other event

If I use the following code

@EventListener
public void onEvent(AbstractEvent abstractEvent) {
}

It should capture all the events including event X as per your previous comment.

That will capture all events. You might want to code it to ignore some Events, rather than run code that looks for a change of your field every time, but you don't really have to. As an example, I would consider ignoring issue delete, comment update and delete, and so on. Events where your field cannot change...

But I am not able to catch event X using the above code. Though I can capture "1. issue updated event" and "2. transition events", which means event X is "3. some other event".

Also it means that the event X is not of AbstractEvent type, that is why I am not able to catch it, which confuses me.

How do I catch event X?

The above code does not work :(

What is wronge here? Why am I not able to catch event X?

Thanks,

Ankit

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 8, 2014

>Let say event X is fired when a custom field for an issue is changed.

For the third time, and I'm running out of ways to say it.

Events are fired by ISSUE changes. When you change an issue (maybe changing your custom field), you could get event X, Y or Z depending on your configuration.

Could we step back from this and look at the actual listener code though. What do you have for overriding workflowEvent(IssueEvent event) ?

Ankit Bhasin April 8, 2014
public class PluginListener implements IssueEventListener {
	@Override
	public void workflowEvent(IssueEvent issueEvent) {
		Long eventTypeId = issueEvent.getEventTypeId();
		Issue issue = issueEvent.getIssue();
	        if(eventTypeId.equals(EventType.ISSUE_CREATED_ID){
        	 	createIssue(issueEvent);
	        } else if (eventTypeId.equals(EventType.ISSUE_DELETED_ID) ) {
	        	deleteIssue(issueEvent);	       
		} else {
	        	updateIssue(issueEvent);
	        }						
	}
}

Thank you NIC for your patience.

Ankit Bhasin November 11, 2014

I think it was happening because of https://jira.atlassian.com/browse/GHS-11149

Honey Sharma July 7, 2017

Hi Ankit,

I do realise that the post is way too old. But did you happen to find a way around this issue?

I have stumbled upon the same issue, when no event is being fired if a custom field(in my case, "Issue Cause") is updated.

Any help /guidance is appreciated.

 

Thanks.

Marc Moroz February 25, 2019

I'm looking for some help/guidance here as well.  I need to catch when the "End Date" field is updated and populated the custom field "Previous End Date" with the old value.

So if the End Date is 2/15 and I change it to 2/20, "Previous End Date" = 2/15 and "End Date" = 2/20.

Suggest an answer

Log in or Sign up to answer