ScriptRunner Listener: Newly created issue not showing in JQL or from parent get methods

Cedacri
Contributor
February 24, 2025

To whom it may concern, 

 

I have the following Listener that has to iterate over the parent issues of the trigger issue, then from the parent to go down and iterate again over its children.

The problem: When doing the aforementioned the script seems to miss the newly created children issue that triggered the event, which is a problem for the Create Issue event types (update Issue works fine).

To get a better understanding of what Im facing, look at this listener code:

The issue created was a subtask for a story, said story already had 1 existing subtask.

It does the following:

- Prints the parent of the trigger issue

- Prints the children of the parent (amongst the children the trigger issue should also appear, but it does not)

- Prints the children of the parent using JQL (amongst the children the trigger issue shoul also appear, but ti does not)

- Prints the trigger issue via JQL (thankfully it yields itself)

- Reindexes the trigger Issue and its parent story and repeats the steps with no success

 

image.png

 

Basically, what Im trying to show is that ScriptRunner (or Jira) somehow glitches here, my first thought was that the listener in question executes too fast and Jira doesn't have time to properly index the issue for it to be accessible programmatically. 

As you can see from the logs, it is somewhat true (at least the JQL returns itself).

I've also tried the same with outwardLinks but no luck there, what is baffling however is that from the script console it instantly yields the correct results after a subtask was created.

Am I doing something wrong here? or is there some peculiarity that I should be aware of for this edge case?

 

EDIT: The same script used in jira automation (Issue created trigger > action: run script) works as intended, in ScriptRunner listener it does not, so Im using the same script with some modifications for this creation edge case. Thoughts?

 

 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 25, 2025

Hi @Cedacri 

You're absolutely right that the listener executes too fast before Jira fully indexes the newly created subtask. Please take it with a pinch of salt, as far as I know, in Jira, listeners execute before the transaction is committed meaning that indexing has not yet taken place when your listener runs. This is why Thread.sleep won't help, it would only delay things. Indexing within the listener would not help because it would only index with the old data, not the committed ones.

I'd suggest using post function script which will run after the indexing post function. Or, you can schedule the script to run later.

 

Cedacri
Contributor
February 25, 2025

@Tuncay Senturk , oh that makes a lot of sense. With Thread.sleep the create form in the GUI takes about ~5 seconds longer indeed before it finishes. Thanks for the explanation.

I ended with using automation rules for this case instead.

Like Tuncay Senturk likes this
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 25, 2025

You're very welcome!

DEPLOYMENT TYPE
SERVER
VERSION
9.17
TAGS
AUG Leaders

Atlassian Community Events