Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Scriptrunner - reindex an issue

I have a report, where issues are displayed in a column. These issues have checkboxes next to them. When the checkboxes are selected and a transition is clicked, then the selected issues are supposed to transition. When the transition is clicked, a jql is performed, and all issues with checkboxes are searched. However, I think since it is not being re-indexed, the issues cannot be found. How do I re-index the issues so they can be found?

1 answer

3 votes
Gaston Valente Community Leader May 23, 2018

Stefan,

Here's a groovy snippet to reindex an issue.

However, issue indexing is automatic after an update, check if you're doing the actions in the right order

Let me know if i can help you with anything else

 import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.index.IssueIndexingService;

MutableIssue mutableIssue = ComponentAccessor.getIssueManager().getIssueObject(issue.getKey());
boolean isIndex = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
IssueIndexingService IssueIndexingService = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);
IssueIndexingService.reIndex(mutableIssue);

ImportUtils.setIndexIssues(isIndex);

Would I place this in the script for the post function?

Gaston Valente Community Leader May 24, 2018

Stefan,

You can place it in a post function or in a listener.

Usually the last post function performs a reindex

Hi @Gaston Valente,

I have created a Script listener by referring your code. But It doesn't work. Can you please look into my code and tell me what i am doing wrong. 

 

import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.Issue;
//import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.index.IssueIndexingService;

import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;

Issue issue = event.issue

//Get issue key
def currKey = issue.getKey();

//Query for all features where linked epic = current key
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser);
def searchProvider = ComponentAccessor.getComponent(SearchProvider);
def issueManager = ComponentAccessor.getIssueManager();
def user = ComponentAccessor.getJiraAuthenticationContext().getUser();

def queryString = 'issuetype = Feature AND "Linked Epics" = ' + currKey;
def query = jqlQueryParser.parseQuery(queryString);
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter());


if (results)
{
results.getIssues().each {documentIssue ->
boolean isIndex = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
IssueIndexingService IssueIndexingService = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);
IssueIndexingService.reIndex(documentIssue);

ImportUtils.setIndexIssues(isIndex);
}
}

Never mind. I fixed it. thanks!

Nallu, how do you solved it?

Hello @nallu 

I'm also interested :-)

What was missing ?

Suggest an answer

Log in or Sign up to answer
TAGS

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