Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom listener for reindex issues, if date of version or sprint is changed

Владислав Яшин August 29, 2019

Hi! Please help.

I want create custom listener, which will perform the re-index issues (which are included in version or sprint), if release date changed.

I have a piece of code, but I can’t figure out how to get the list of issues in the release and reindex its.

def issueManager = ComponentAccessor.getIssueManager()
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
Version version = event.getVersion()

????
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
log.warn("Reindex issue ${issue.key} ${issue.id}")
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);

2 answers

0 votes
Nic Brough -Adaptavist-
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.
September 5, 2019

I think you have the right idea here - you've found the right bit of the doc about when scripted fields are updated (I don't like our docs much, as the really useful bit you've found is well buried and should be a lot more obvious but they are being reviewed and rewritten). 

@JiraGuyis right in that it would be better to have the release date built automatically, but as it's a scripted field, the problem lies with the fact that there's no way for that field to know that something not directly related to the issue should trigger an update.  It's not really a bug in Jira or Scriptrunner, just a hole in the functionality that falls down the gap between them!  So your listener is the right idea, as it can tell those fields to update.

Short answer - there's a chunk of code at https://library.adaptavist.com/entity/perform-a-jql-search-in-scriptrunner-for-jira that iterates over a search result.  Feed it with "version = <version that just changed>" to get a list of issues, then you can iterate over that with your indexing code (although I might swap to "issueIndexingService.reIndexIssueObjects(<list of issues>)" )

0 votes
jira guy
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.
August 29, 2019

JIRA already does incremental indexing. Why do you want to add this extra step?  

Владислав Яшин August 29, 2019

I use this for a script field that displays the end date of the release. If the release date changes, then this does not lead to indexing of issues and because of this, sorting in the search for requests does not work.

jira guy
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.
August 29, 2019

I am still not sure. But I don't think this is the right way to approach this. I would recommend creating a support ticket with Atlassian. Search is something that should work in JIRA and if it isn't working, you have a problem with JIRA my friend.

Владислав Яшин August 29, 2019

Unfortunately, this is a feature of the script fields ScriptRunner =(

From the docs

It’s worth expanding a little on what I said above. You can only reliably use a calculated field to display a value that is based on the issue’s fields, or subtasks' fields, or linked issues. The reason why is because the value in the Lucene index is only updated when the issue is updated. If you compute some value based on data outside of the current issue, the value in the index may differ from the value displayed on the issue.

https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html

jira guy
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.
August 29, 2019

I haven't been using this plugin for sometime now. It all makes sense now. 

You might already know this.

If you have Atuomation for JIRA plugin, they have an event for Version Updated. You can then use their third party integration script-runner to execute your script. 

 

Screen Shot 2019-08-29 at 11.21.45 AM.png

Владислав Яшин August 29, 2019

The problem is to select all issues related to the version

Suggest an answer

Log in or Sign up to answer