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
You mention that re-indexing helps; it's definitely an indexing issue. Can you share how you update the issue in your listener?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
It works for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.