Reindex after transition by scriptrunner Edited

Hi everyone,

I got a problem similar to the one described here, with difference that there was described an update issue problem, and now it is a transition issue problem. 

So in general it looks like this:

I do auto transition of several subtasks in script post function by scriptrunner and mostly it is fine except some issues (usually one of all) are not being reindexed properly. So issue is actually in the right status, but before I update it in any other way it appears in the old status in search. 

Here is my code:

Integer actionId = actionI.intValue()

if (!issueInputParameters) {
issueInputParameters = ComponentAccessor.issueService.newIssueInputParameters();
}

IssueService.TransitionValidationResult transitionValidationResult = ComponentAccessor.issueService.validateTransition(applicationUser, issue.id, actionId, issueInputParameters)

log.debug logPref + "Transitioning issue: " + issue.id + " transitionValidationResult " + transitionValidationResult

if (transitionValidationResult.isValid()) {
IssueService.IssueResult transitionResult = ComponentAccessor.issueService.transition(applicationUser, transitionValidationResult)
if (transitionResult.isValid()) {
log.debug 'Issue transitioned. Action Id: ' + actionId
ReindexIssue(issue, logPref)
} else {
log.error 'Error executing transition with action Id ' + actionId
}
} else {
log.error logPref + "Validation error: " + transitionValidationResult.getErrorCollection()
List<String> errorList = new ArrayList();
errorList.addAll(transitionValidationResult.getErrorCollection().getErrorMessages());
for (int i = 0; errorList != null && i < errorList.size(); i++) {
log.error 'Error validating transition with action Id ' + actionId + ' :' + errorList.get(i);
}
}

static void ReindexIssue(Issue anIssue, String logPref) {
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getIssueIndexManager().reIndex(anIssue)
ImportUtils.setIndexIssues(wasIndexing);
}

Post Function is located right after storing to DB before reindexing. 

JIRA version is 6.4.7 and Scriptrunner is 3.1.3

Any help would be appreciated. 

3 answers

1 accepted

1 vote
Accepted answer

It is fixed!

Actually it is quite dumb bug:

it was caused by Additional Reindex function, absolutely redundent in this case, as Reindex is a standard Post Function for each and any transition. 

In my case Reindex was added to fix a very similar but sligtly different bug, that bug was at the end fixed in a different way, but Reindex wasn't removed and caused described bug. 

Good luck to anyone who reads this!

 I tried to make some changs to your script, but I did not test it:

import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.bc.issue.IssueService

Integer actionId = actionI.intValue()

if (!issueInputParameters) {
issueInputParameters = ComponentAccessor.issueService.newIssueInputParameters();
}

IssueService.TransitionValidationResult transitionValidationResult = ComponentAccessor.issueService.validateTransition(applicationUser, issue.id, actionId, issueInputParameters)

log.debug logPref + "Transitioning issue: " + issue.id + " transitionValidationResult " + transitionValidationResult

if (transitionValidationResult.isValid()) {
IssueService.IssueResult transitionResult = ComponentAccessor.issueService.transition(applicationUser, transitionValidationResult)
if (transitionResult.isValid()) {
log.debug 'Issue transitioned. Action Id: ' + actionId
ReindexIssue(issue, logPref)
} else {
log.error 'Error executing transition with action Id ' + actionId
}
} else {
log.error logPref + "Validation error: " + transitionValidationResult.getErrorCollection()
List<String> errorList = new ArrayList();
errorList.addAll(transitionValidationResult.getErrorCollection().getErrorMessages());
for (int i = 0; errorList != null && i < errorList.size(); i++) {
log.error 'Error validating transition with action Id ' + actionId + ' :' + errorList.get(i);
}
}

static void ReindexIssue(Issue anIssue, String logPref) {
boolean wasIndexing = ImportUtils.isIndexIssues()
//log.debug("Reindex issue ${issue.key} ${issue.id}")
ImportUtils.setIndexIssues(true)
IssueIndexingService indexing = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class)
indexing.reIndex(anIssue)
ImportUtils.setIndexIssues(wasIndexing)
}

I think part of your problem is trying to use getIssueIndexManager() from ComponentAccessor. This is no longer possible as it was deleted. See this link.

Hi Joshua,

Thanks for your reply! By your link I get following:

We were unable to find the page you're looking for.

And I can't use IssueIndexingService, I guess it is because I use ScriptRunner 3.1.3 and it wasn't introduced yet there. 

Hey Viktor,

I edited my code to remove the IssueIndexingService. It looks like IssueIndexManager does still exist, but just needs to be accessed with ComponentAccessor.getComponent(IssueIndexManager).

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.util.ImportUtils

Integer actionId = actionI.intValue()

if (!issueInputParameters) {
issueInputParameters = ComponentAccessor.issueService.newIssueInputParameters();
}

IssueService.TransitionValidationResult transitionValidationResult = ComponentAccessor.issueService.validateTransition(applicationUser, issue.id, actionId, issueInputParameters)

log.debug logPref + "Transitioning issue: " + issue.id + " transitionValidationResult " + transitionValidationResult

if (transitionValidationResult.isValid()) {
IssueService.IssueResult transitionResult = ComponentAccessor.issueService.transition(applicationUser, transitionValidationResult)
if (transitionResult.isValid()) {
log.debug 'Issue transitioned. Action Id: ' + actionId
ReindexIssue(issue, logPref)
} else {
log.error 'Error executing transition with action Id ' + actionId
}
} else {
log.error logPref + "Validation error: " + transitionValidationResult.getErrorCollection()
List<String> errorList = new ArrayList();
errorList.addAll(transitionValidationResult.getErrorCollection().getErrorMessages());
for (int i = 0; errorList != null && i < errorList.size(); i++) {
log.error 'Error validating transition with action Id ' + actionId + ' :' + errorList.get(i);
}
}

static void ReindexIssue(Issue anIssue, String logPref) {
def issueManager = ComponentAccessor.getIssueManager()
def indexManager = ComponentAccessor.getComponent(IssueIndexManager)
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
indexManager.reIndex(issueManager.getIssue(anIssue.id));
ImportUtils.setIndexIssues(wasIndexing);
}

 

I have a loop of several issues to transition them all. 

Any number of first ones are transitioned and reindexed well, except the very last one. The last issue is always transitioned, but never reindexed. 

If I just update it, like place a new comment into it or change value in any field it is reindexed and looks descent, but untill then I have this issue. 

 

So loop is based on filter results, by filter I get about 6-10 issues (number doesn't really matter).

So even if I Add to the filter one more issue, of the same issue type, but which does not really belong there, at the end I have two unreindexed issues: the one I always get (the last one in the filter results) and the one I added. 

So the question is: why doesn't reindex work for the last issue? And why doesn't it work for the added issue? 

Originally in the filter are sub-tasks of a parent, and the one I added was the subtask of different parent. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,447 views 0 8
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