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);
}
Hello,
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();
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.