Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Search shows old issue summary

Viktor Kuzmychov December 6, 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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 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 December 12, 2016

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

1 vote
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 7, 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 December 7, 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 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 December 9, 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. 

0 votes
Viktor Kuzmychov December 8, 2016

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

0 votes
Bhushan Nagaraj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 6, 2016
Viktor Kuzmychov December 7, 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 December 7, 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 =

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events