JQL results in script listener does not include the updated issue Edited

I want to create a new listener using Scriptrunner, to send email in case someone adds an issue to current sprint (and so change the scope of the sprint). 

The listener is fired on issueUpdate event and I am checking if the issue is returned by the following JQL: 

issueFunction in addedAfterSprintStart('DevOps All')

The problem is, that the current issue is not returned (probably index problem?) and so I cannot verify if the issue has been added to the current sprint. 

Any idea, how to ensure that the JQL returns also the issue that has been updated? Manual reindex before searching or waituntil (examples of the implementation would be very helpful)? 


Here is the full code: 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger


SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def myJQL = "issueFunction in addedAfterSprintStart('DevOps All')"
List<MutableIssue> issues = null

SearchService.ParseResult parseResult = searchService.parseQuery(user, myJQL)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
// Transform issues from DocumentIssueImpl to the "pure" form IssueImpl (some methods don't work with DocumentIssueImps)
issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}

if (issues.any { it==issue.key } && changeItems.any { it.get('field')=='Sprint' }) {
//send email
log.info("ScriptListener: Sprint scope has been changed by adding '" + issue.key + "' to the sprint in DOSTACK project.");
} else {
log.info("ScriptListener: Sprint scope didn't change for the board 'DevOps All' in DOSTACK project (Issue: " + issue.key + ").");
} else {
log.error("ScriptListener: Invalid JQL - " + myJQL);


1 answer

0 votes


You can try to reindex the issue before calling the JQL function. You can find the code here


But how do you fire your trigger? Do you change a value on the edit screen or it is fired from a transation?

Hello Alexey, 

yes, I tried that one, but it looks like it has no effect on the query search. 

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)

boolean wasIndexing = ImportUtils.isIndexIssues();

The first log entry is output from JQL "issueFunction in addedAfterSprintStart('DevOps All') and second is the current issue that has been updated and is missing from the search result. 

2017-11-23 23:22:05,041 INFO [utils.ConditionUtils]: [DOSTACK-2692, DOSTACK-2556, DOSTACK-2472, DOSTACK-2450, DOSTACK-1900, DOSTACK-1844, DOSTACK-1843, DOSTACK-1842, DOSTACK-1839, DOSTACK-1838, DOSTACK-1837, DOSTACK-1835, DOSTACK-1834, DOSTACK-1793, DOSTACK-1215, DOSTACK-876, DOSTACK-253, DOSTACK-172]
2017-11-23 23:22:05,042 INFO [utils.ConditionUtils]: DOSTACK-2479

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

478 views 8 28
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you