Detecting cascading event

I’d like to create a ScriptRunner listener that updates the issue, in a way that sends the “issue updated” event to trigger (cascade to) some other listeners. Firing that event will call original listener again, with some performance overhead, log noise, and some risk of infinite loop.

Imagine two listeners:

  1. When field X changes, then put the value in Y. If Y changes, revert it to contain value of X. IOW keep two fields in sync.
  2. When Y changes, then update some other field Z.

What happens is:

  1. X changes, so we update Y.
  2. That update calls listener 1 again, which now needs nontrivial logic for “loop detection”. And it’s wasting precious time.
  3. That update calls listener 2. It updates Z.
  4. Updating Z calls listener 1 and 2 again. More complexity and wasted time.

How can I prevent this?

Is some kind of thread-local storage available in SR?

Is there a utility somewhere in ScriptRunner or Jira that would let me identify the event/listener chain that has been executed on the thread so far?

Both IssueService and IssueManager update methods provide a mechanism for firing specific events or not sending emails.

IssueManager issueManager;
IssueService issueService;
ApplicationUser applicationUser;
MutableIssue mutableIssue;
IssueInputParameters issueInputParameters;
Logger log;

// issuemanager
Issue myUpdatedIssue = issueManager.updateIssue(applicationUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);

IssueUpdateValidationResult validationResult = issueService.validateUpdate(applicationUser, mutableIssue.getId(), issueInputParameters);
if ( ! validationResult.isValid() ) {
  log.error (validationResult.getErrorCollection().toString());

IssueResult issueResult = issueService.update(applicationUser, validationResult, EventDispatchOption.DO_NOT_DISPATCH, false);
if ( ! issueResult.isValid() ) {
  log.error (issueResult.getErrorCollection().toString());

So the trick would be to call one of these methods and pass in the appropriate static member from EventDispatchOption.

Thanks. I am aware of that, but I’m looking for options when I actually do want to use ISSUE_UPDATED. Some kind of thread-local storage (not sure if ThreadLocal in Script Runner script would actually work/persist). Or Jira or Script Runner service, kind of like higher-level stacktrace that would let me identify all events currently on the stack.