Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner update always running twice

Stefan Fuhrmann April 9, 2023

Hey,

I created a "Script Listener" with Scriptrunner for my Jira Cloud project.

Whenever an Issue is created or updated, the script will adapt the summary based on some cool rules. This part is working fine and I'm kinda happy.

However, as I'm changing the summary, the script will call again (as changing the summary is an update). 
This second call is just a waste of time, as nothing will be changed, as nothing changed.

Can I somehow avoid it?
I tried 'If the following condition evaluates to true:', hoping it will be my user for the first call and the ScriptRunner user for the second, but it seems to be always the "as this user" user.

Thanks!

2 answers

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2023

Jira fires all the relevant events on a change now, so your listener is simply responding to multiple events.  Change the list to just "update", ignore the create event.

Stefan Fuhrmann April 12, 2023

The create even isn't a problem. I want to run the script whenever there is a change on the issuse. The first change is the "create".

Whenever something is changed in the issue, I check some custom fields and adapt the summary based on these field. Adapting the summary (via script) is a change on the issue, so the update event is triggered again and the script is executed again. Luckly there is no real change, so no need to change the summary, so no endless loop. But it's 100% unnecessary to run twice.

0 votes
Alex Koxaras -Relational-
Community Champion
April 9, 2023

HI @Stefan Fuhrmann 

When do you want your listener to run? On create, on update or both? If you don't want your script to run on update, then why you don't remove it from the listener? Do you want it to run on update for all e.g. field changes, but the summary?

Stefan Fuhrmann April 12, 2023

Hey @Alex Koxaras -Relational-

I want to run the listener on both (create & update).

The problem is, I change (update) something in the issue inside the script, which will trigger a new update event, resulting in running the script twice. Luckly it's no endless loop, as I don't change something the second run. But no point in running it twice.

I was thinking of checking the "changer/creator" in the "If the following condition evaluates to true" part of the script. As the "changer/creator" would be a user for the first run and the script in the second run. But I don't think the "changer/creator" is available at this point.

Like Marius Schneidermann likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events