JQL results in script listener does not include the updated issue

Miroslav Kralik November 23, 2017

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 votes
Alexey Matveev
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.
November 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?

Miroslav Kralik November 23, 2017

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
TAGS
AUG Leaders

Atlassian Community Events