It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Reindex after transition by scriptrunner Edited

Viktor Kuzmychov Jul 14, 2017

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
Answer accepted
Viktor Kuzmychov Jul 19, 2017

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!

0 votes
Joshua Yamdogo [Adaptavist] Community Leader Jul 17, 2017 • edited

 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.

Viktor Kuzmychov Jul 18, 2017

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. 

Joshua Yamdogo [Adaptavist] Community Leader Jul 19, 2017

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);
}

 

0 votes
Viktor Kuzmychov Jul 18, 2017

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. 

 

Viktor Kuzmychov Jul 19, 2017

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

scaling agile at the enterprise level with Valiantys

Hey there Community! My name is Vannya Vallejo, the Channel Communication Specialist at Atlassian and I want to help Atlassian users like you learn about our Solution Partners and how they can help ...

431 views 1 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you