Custom Field Update Listener

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

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)

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

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...

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

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

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

>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) ?

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.

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.

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published yesterday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

50 views 0 3
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot