ScriptRunner - Reindex script field Best Practice

Shlomi Perets August 29, 2018

Hi

I want to know if i'm doing things right,

In my Jira i'm using Requirement above Epic (with custom link that i've created)

I've created a script field on all my issues type that displays the 'Req Link' just like the 'Epic Link that Out of the box, It works fine!)

The thing is that unless i'm doing re-index lets say every hour, the search results are not correct (if i'm filtering by this 'Req Link' field.

So, i understand i need to do re-index but what is the best practice for that?
- Can i add it to my 'script field' script? (re index just this field?)
- Do i need to create a listener (and which one) to re index all issues all the time?

 

Please advise.

Thanks,

1 answer

1 vote
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 29, 2018

Hi Shlomi,

The right way to do it is:

Instead of scriptedfield, create regular customfield.

Than, in listener, update that regular customfield with the value you want, and inside the listener, after updating the value in the customfield, make re-index.

 

You can't re-index from scriptedfield as it fails and throw exception of "stackoverflow"

Shlomi Perets August 29, 2018

Hi,

Thanks For the quick reply,

In my case my company uses Jira for over a year now with a lot of Issues in the system about now, What i was asked to is to add this calculated 'Req Link' to all the issues (all over the hierarchy).

The way you describe is cool except I'll need to 'edit' all the issues in Jira so the change will take effect and I'll see the 'Req Link' field updated.

As i said,  the approach i was going gave me the result i want but i need to preform re-index in time to time so the JQL will be correct.

Is it right to create a listener or some other script that will run every hour and will re-index only the 'Req Link' field in the issues? is this possible?

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 29, 2018

Than lets go for another approach.

keep your scripted field.

at the end of your scripted field, fire event (of your choice).

Create a listener that will listen to the event you fire from the scripted field, in that listener just run re-index for the issue fired the event (which is the issue run the scripted field)

 

Here is the code to re-index from the listener (that's all you need to put there)

import com.atlassian.jira.issue.index.IssueIndexingService;

def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
issueIndexManager.reIndex(event.issue) 
Like SWAPNIL SRIVASTAV likes this
Shlomi Perets August 29, 2018

Sounds good, I'll give it a try.

Thanks.

Shlomi Perets September 5, 2018

@Nir HaimovCan you please give an example code for event firing to put at the end of my scripted field?

Thanks,

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 5, 2018
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption

issueManager.updateIssue(user, (MutableIssue)issue, EventDispatchOption.ISSUE_UPDATED, false);
Shlomi Perets September 25, 2018

Thanks for the example but its not working, Getting an error.

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 25, 2018

what is the error?

Rodolfo So June 27, 2023

Hi @Nir Haimov 

 

Can you provide screenshot on this configuration from your scripted field and scriptrunner listener?

 

Thank you!

Suggest an answer

Log in or Sign up to answer