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

Logger.getLogger(
"com.onresolve").setLevel(Level.INFO)

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 vote
Alexey Matveev Community Champion Nov 23, 2017

Hello, 

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

https://community.atlassian.com/t5/Answers-Developer-Questions/Issue-reindex-from-groovy-script/qaq-p/509901

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();
ImportUtils.setIndexIssues(true);
issueIndexingService.reIndex(issue);
ImportUtils.setIndexIssues(wasIndexing);

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

844 views 2 9
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