Hi,
I have a scenario where I need to re-index the issue whenever a linked issue is updated.
Here is the details.
Actually, We are linking a epic with issue type feature through a custom field (issue picker). This feature issue has some scripted fields which is calculating data based on the data in linked epics. But, These data doesn't get updated correctly in JQL filter as indexing is not happening on the feature issue whenever script field is getting updated.
So, I have written a script listener to re-index the feature issue whenever the issue type epic is created/updated.
Here is the code,
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.index.IssueIndexingService;
//import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;
Issue issue = event.issue
//Get issue key
def currKey = issue.getKey();
//Query for all features where "Linked Epics" ~ current key
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser);
def searchProvider = ComponentAccessor.getComponent(SearchProvider);
def issueManager = ComponentAccessor.getIssueManager();
def user = ComponentAccessor.getJiraAuthenticationContext().getUser();
def queryString = 'issuetype = Feature AND "Linked Epics" ~ ' + currKey;
def query = jqlQueryParser.parseQuery(queryString);
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter());
//log.warn("Reindex issue ${issue.key} ${issue.id} ${currKey} ${results.getIssues().size()}+++++++++++++++")
if (results)
{
results.getIssues().each { documentIssue ->
boolean isIndex = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
IssueIndexingService IssueIndexingService = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);
IssueIndexingService.reIndex(documentIssue);
ImportUtils.setIndexIssues(isIndex);
}
}
It looks like, this script listener works fine. But still JQL result is not getting updated correctly and its inconsistent. So, I had to manually re-index the project on a frequent basis.
Can anyone tell me whats wrong with the script? OR is there any other issue?
Any help would be greatly appreciated.