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

Search shows old issue summary

Viktor Kuzmychov Dec 06, 2016

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

1 vote
Answer accepted
JamieA Dec 11, 2016

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

 

Viktor Kuzmychov Dec 12, 2016

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

1 vote
Jonny Carter Dec 07, 2016

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.

Viktor Kuzmychov Dec 07, 2016

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. 

JamieA Dec 09, 2016

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?

 

Viktor Kuzmychov Dec 09, 2016

@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. 

Viktor Kuzmychov Dec 07, 2016

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)
Viktor Kuzmychov Dec 07, 2016

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 =
0 votes
Viktor Kuzmychov Dec 08, 2016

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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Statuspage

⭐️Would you recommend Statuspage? Leave a (honest!) review. ⭐️

Hi Community friends, We're working on sourcing more reviews on Capterra – a popular software review site –  to help teams like yours make more informed decisions when choosing an inc...

82 views 3 5
Join discussion

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