Changing custom field in Listener not re-indexing issue

Scott Evans September 27, 2018

I am using JIRA 7.3.6 and Adaptavist scriptrunner 5.4.28

I have a Groovy Listener that changes a custom field value when either issueCreated or issueUpdated events happen. The field is being updated but a JQL search using that field does not give the correct results until the database is re-indexed.

log.debug "Updating Train field."
CustomFieldManager  cfm          = ComponentAccessor.getCustomFieldManager()
def relTrainField = cfm.getCustomFieldObjects(issue).find {it.name == "ReleaseTrain"}
def changeHolderTrain = new DefaultIssueChangeHolder();
relTrainField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(relTrainField), newRT),changeHolderTrain);

Is there a better way to do this custom field change that will re-index the issue also?

Most examples that I can find for re-indexing use IssueIndexManager or IssueIndexService. When I try to use those, I get errors as if those have been deprecated.  Is there a way to re-index an issue using the 7.3.6 API?

Thanks for any help

1 answer

1 accepted

2 votes
Answer accepted
fjodors
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 28, 2018

Hi George

 

I am using such listener code to update custom field value, try it

MutableIssue issueToUpdate = (MutableIssue) event.issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getIssueManager();

def cfield = customFieldManager.getCustomFieldObjectByName('<field name>');
issueToUpdate.setCustomFieldValue(cfield, <value>);
issueManager.updateIssue(event.getUser(), issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false);
Scott Evans September 28, 2018

That worked. I also notice one of the other Listener used the following without any errors.

def issueIndexingService = ComponentAccessor.getComponentOfType(IssueIndexingService.class)

issueIndexingService.reIndex(issue);
Like Markus_COGNITIFF likes this

Suggest an answer

Log in or Sign up to answer