Forums

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

ScriptRunner updating fields not displaying in JQL Searches

Roberto L
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 1, 2019

Hi Community,

Run into an issue where I have a ScriptRunner listener that runs and in the listener updates the value of a JIRA field. For Example, custom field with name Production owner gets a value of "Roberto".

When I go to the issue and check the Production Owner field I can see in interface that it has been updated to "Roberto" per the listeners script.

When I search for issue using JQL and i type for example:

issue = HTP-197 AND Production Owner is Empty.

Instead of displaying me nothing, it displays HTP-197. Categorizing it as if Production owner field is Empty, when it is not.

Is there something specific needed to be done at Listener level to ensure JIRA pushes values to DB for it to appear correctly in JQL. This problem goes away usually after re-indexing or just waiting a day or so.

Thanks for the insight and help!

-Roberto

 

3 answers

1 vote
Payne
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 1, 2019

You mention that re-indexing helps; it's definitely an indexing issue. Can you share how you update the issue in your listener?

Roberto L
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 6, 2019

hey @Payne 

Below is my code to update values of a field in a listener.

def modifyValue(ApplicationUser user, Issue issue, CustomField customField, String value){

IssueService issueService = ComponentAccessor.getComponent(IssueService);
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.addCustomFieldValue(customField.id, value)
def update = issueService.validateUpdate(user, issue.getId(), issueInputParameters)
if (update.isValid()) {
issueService.update(user, update)
}

}

Do I need to add code to manually force a re-index?

Thanks!

-Roberto

Payne
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 6, 2019

You may consider including an explicit re-index of the issue within your script by adding the following after your update statement:

def indexManager = ComponentAccessor.getComponent(IssueIndexingService.class)
indexManager.reIndex(issue)

You'll need this import:

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

Like # people like this
0 votes
PD Sheehan
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 1, 2019

There are several actions you can take throughout scriptrunner that will not update the index automatically.

When you use workflow post functions,  since the workflow will typically have a "reindex issue" function by default, then your actions will be accounted for by the re-index task.
If your script is after that re-index task in the sequence, then the actions will not be indexed.

In that last example and everywhere else, you have to take care of that yourself.

Generally, I use this sequence:

import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService

boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(event.issue)
ImportUtils.setIndexIssues(wasIndexing)

I am not sure when ImportUtils.isIndexIssues() is ever false. In my environment, it seems to always be true and when I manually set it to false, it gets re-set to true the first time I save an issue.  But if it is false, the reIndex(issue) method will not be successful. So just to be sure, I always check the state before and return to the prior state after indexing.

0 votes
Hana Kučerová
Community Champion
August 1, 2019

Hi,

recently I've written a script, which updates custom field after issue is created. 

There are two actions at the end of the script:

  1. issue.setCustomFieldValue(...)
  2. issueManager.updateIssue(...)

It works for me.

Suggest an answer

Log in or Sign up to answer