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.
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 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, recently i've ben struggling with this problem.
I've created a scriptrunner script, that was executed during the transition.
And it seems that when you call a transition postfunction that makes another transition - the new transition will success, but your STATUS field won't be changed.
So i came up with the idea of explicitly changing the status.
Code:
if (transitionResult.isValid()){
issue.setStatus(transitionResult.getIssue().getStatus())
def updated_issue = issueManager.updateIssue(approver, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
And now it's works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.