Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Avoiding cascading events

Tom Kostiainen May 8, 2016

Hi,

Working on a cusom script runner listener that sets the sprint of a issue automatically. My problem is that when this happens the listener is triggered twice, first for the user action and a second time because the field gets set.

Any way to avoid this?

Br,
Tom

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
JamieA
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.
May 9, 2016

I'm not sure how you are setting the sprint, please include your code.

There are ways to update an issue without firing an event, for example:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager

def issueManager = ComponentAccessor.getComponent(IssueManager)
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("...")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = issueManager.getIssueObject("JRA-327")
issue.setCustomFieldValue(cf, 42)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

If you use the IssueService to update it I don't think you can avoid firing an event, because it's a high-level interface that tries to emulate exactly the way the UI behaves.

You might try using the built-in function to add/remove an issue from a sprint.

The other way to set the sprint is using com.atlassian.greenhopper.service.sprint.SprintIssueService#moveIssuesToSprint, which may not fire an event.

Tom Kostiainen May 10, 2016

Thank you for your reply! I'm using the SprintIssueService and it seems to fire an event.

Is is there a way to set the sprint field using only the setCustomFieldValue as you mentioned?

Or does the updateIssue call have an effect even when the issue passed by the event is not mutable and the SprintUssyeService is used? (Script runner is now insists on showing only "No failures in the last 15 execution(s)" so I get no feedback on if adding this had any effect)

 

TAGS
AUG Leaders

Atlassian Community Events