Forums

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

Determining event origin in Scriptrunner Listener (cascading events)

Daniel Garcia August 22, 2023

I need to write a listener that changes the rank of a related issue when an issue rank changes. This will cause a new LexoRankChangeEvent and in some cases I'll end up in an infinite loop.

Is there any way of determining why the event occurred? (was it triggered from my script or something else?)

 

1 answer

0 votes
PD Sheehan
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.
August 28, 2023

I'm not sure if what you are asking for is available directly.

But here is an option that might work: ensure your listener is running as a different user when making the change.

And in your script, if the current user is your listener actor, then skip the change.

This way, it will only trigger once when changes are initiated by other users.

 

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def listenerActor = CompoentAccessor.userManager.getUserByKey('Rank Automaton')

if(currentUser == listenerActor) return

try{
ComponentAccessor.jiraAuthenticationContext.loggedInUser = listenerActor
//the rest of your script

} finally {
ComponentAccessor.jiraAuthenticationContext.loggedInUser = currentUser
}

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events