Search shows old issue summary

Hi!

I have just wrote a listener, which updates summary of Sub Tasks if summary of a parent task is changed. It works fine except one thing:

Search always shows previous version of summary of Sub Tasks. 

I did reindex, but that doesn't help. Reindex function looks like this:

void ReindexIssue(Issue anIssue, String logPref) {
    if (log.isDebugEnabled()) {
        log.debug logPref + "Reindexing issue " + anIssue.getKey()
    }
    boolean wasIndexing = ImportUtils.isIndexIssues()
    ImportUtils.setIndexIssues(true)
    ComponentAccessor.getIssueIndexManager().reIndex(anIssue)
    ImportUtils.setIndexIssues(wasIndexing);
}

Every time in search I can see previous version of summary, however if I open Sub Task I can see the correct one. 

 

Thanks in advance. 

4 answers

1 accepted

In trying to debug your problem I wrote the script from scratch more or less coming up with the below.

The problem is your EventDispatch option - if you say DO_NOT_DISPATCH then the indexer does not receive notification that it needs to reindex. This worked for me:

https://gist.github.com/jechlin/2767e05f2ec75acffb6579b025d230b9

 

Hi @Jamie Echlin (Adaptavist), solution seems to work for me, thank you so much!

What mechanism are you using to update the subtasks? I'd strongly recommend using IssueService.update in order to update the sub-tasks. The IssueService class makes sure business logic, like automatic reindexing, gets followed, where the IssueManager may not always do so. It's a bit more elaborate though, as you need to get a validation result first. You can see an example on https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/select-list-other.html. It's doing other things, but the thrust of it is

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
//...
def faveFruitOtherFld = customFieldManager.getCustomFieldObjectByName("Favourite Fruit (Other)")
def issueService = ComponentAccessor.getIssueService()
    def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    def issueInputParameters = issueService.newIssueInputParameters()
    issueInputParameters.with {
        addCustomFieldValue(faveFruitFld.idAsLong, option.optionId.toString())
        addCustomFieldValue(faveFruitOtherFld.idAsLong, null)
    }
    def updateValidationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters)
    if (updateValidationResult.isValid()) {
        issueService.update(currentUser, updateValidationResult)
    }

That code isn't complete on its own, but it should suggest how to build the issueInputParameters and pass them to validateUpdate.

Hi Jonny,

I have similar function:

void UpdateIssue(Issue updatedIssue, ApplicationUser applicationUser, IssueInputParameters issueInputParameters) {

    ApplicationUser loggedInApplicationUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
    ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(applicationUser)

    IssueService.UpdateValidationResult updateValidationResult = ComponentAccessor.issueService.validateUpdate(applicationUser, updatedIssue.id, issueInputParameters)

    if (updateValidationResult.isValid()) {
        IssueService.IssueResult updateResult = ComponentAccessor.issueService.update(applicationUser, updateValidationResult, EventDispatchOption.DO_NOT_DISPATCH, false)
        if (updateResult.isValid()) {
            log.debug 'Issue updated: '
        } else {
            log.error 'Error updating issue'
        }
    } else {
        List<String> errorList = new ArrayList();
        errorList.addAll(updateValidationResult.getErrorCollection().getErrorMessages());
        for (int i = 0; errorList != null && i < errorList.size(); i++) {
            log.error 'Error validating update' + errorList.get(i);
        }
    }

    ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(loggedInApplicationUser)
}

And also I have this one 

void UpdateSummary(Issue anIssue, String devSummary, String logPref){
    log.debug logPref + "Issue: " + anIssue.key + " Summary: " + devSummary
    MutableIssue mutableIssue = ComponentAccessor.getIssueManager()getIssueObject(anIssue.key)
    mutableIssue.setSummary(devSummary)
    ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), mutableIssue, UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_DELETED).sendMail(false).build())
}

They both work, but result is the same, search shows old summary. 

The first one should work. The second one will update the issue but without reindexing.

Are you sure the listener is only firing on the parent tasks, and not firing on both parents or subtasks?

 

@Jamie Echlin (Adaptavist) I have just updated listener to fire only on parent issue type, but result is still the same, summary is updated, but filter shows previous summary. 

FYI: same code in Post Function works exactly as expected, e.g. filter shows proper results. 

Hi Brushan,

I have 6.4.7 JIRA, and unfortunately I can't import this class

unable to resolve class com.atlassian.jira.issue.index.IssueIndexingService
 @ line 29, column 1.
   import com.atlassian.jira.issue.index.IssueIndexingService
   ^
1 error
        at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
        at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943)
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:590)

Tried also to use it like this:

IssueIndexingService indexing = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);

But got:

unable to resolve class IssueIndexingService
 @ line 125, column 42.
            IssueIndexingService indexing =

Does anyone else have any ideas? @Jamie Echlin (Adaptavist) ?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Agile

How Scrum works? It starts with training and education

To answer “How scrum works,” most of the teams I've worked with first addressed the question: “where to start?”  That question applies to both implementation and improvements on the Scrum framew...

221 views 3 7
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