Custom field value not updated in the Index

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2019

Hello All,

I am using the Script Runner plugin and writing a custom listener. When a user updates a custom field of type Version picker (single) called "Service  Increment" on an epic then my listener automatically updates the same custom field with same value on the child stories. This functionality is working perfectly fine. 

Now, the problem is that when I run a JQL query like

type = story and "Service Increment" = SI-04

then it's unable to find the newly updated child story which has inherited the value SI-04 from the parent epic.

I have tried following approaches to update custom field value so that it's reflected in the index but it's just not working.

Approach 1

Using the updateValue method on the custom field object for the story object, it has always been working well with all custom fields and the value is also reflected in the index immediately but in this case it's just not working. It updates the value perfectly in the story but it's not reflected in the JQL

serviceIncrement.updateValue(null, story, new ModifiedValue(null, serviceIncrementValue), new DefaultIssueChangeHolder())

 

Approach 2

Using the issueManager, again this works well but the value is not appearing in the JQL

story.setCustomFieldValue(serviceIncrement, serviceIncrementValue)
issueManager.updateIssue(user, story, EventDispatchOption.ISSUE_UPDATED, false)

 

Approach 3

Using the IssueService and IssueInput parameters, and again same result value is updated on the story but not appearing in JQL

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.addCustomFieldValue(serviceIncrement.getId(), serviceIncrementValue.first().getId().toString())
def validateUpdate = issueService.validateUpdate(user, story.id, issueInputParameters)
if (validateUpdate.isValid()) {
def issueResult = issueService.update(user, validateUpdate, EventDispatchOption.ISSUE_UPDATED, false)
if (issueResult.isValid()) {
log.info "${issue.key} has been updated with new SI version"
} else {
log.error "${issue.key} failed to update the SI version" + issueResult.errorCollection.errorMessages
}

 

Approach 4 

Adding the explicit indexing code and still the same result as above

serviceIncrement.updateValue(null, story, new ModifiedValue(null, serviceIncrementValue), new DefaultIssueChangeHolder())

def issueIndexService= ComponentAccessor.getComponent(IssueIndexingService.class)
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
issueIndexService.reIndex(story)
ImportUtils.setIndexIssues(wasIndexing)

And still the same results.

The only way to get the newly updated value immediately reflected in the JQL is by doing a complete project reindex.

Thus, please share your opinion.

Jira version - 7.11.2

Thanks,

Tarun

 

 

4 answers

0 votes
Ming P April 14, 2020

Thanks a lot.  

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2019

Thanks all for the reply, it's now working fine after reindex, and removing the listener and adding it again. 

0 votes
Marc Minten _EVS_
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.
January 23, 2019

I do your approach 2 (setCustomFieldValue and then updateIssue) followed by the second part of your approach 4 (the reindex part), and it works fine!

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2019

Hello 

I tried the approach of issueManager plus the explicit reindex code but that didn't work as well. 

Marc Minten _EVS_
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.
January 23, 2019

Hmm, I use this in several scripts/listeners, and it works fine. The only difference I see is that we do not dispatch further events to the modified issue (

….EventDispatchOption.DO_NOT_DISPATCH….

We also are on Jira 7.4.3, did you check in the release notes something changed regarding the indexing API ?

Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2019

I would definitely expect Approach 4 (reindex the issue) to be necessary

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2019

Yes, I re-index the complete system and would try these approaches again. It generally works well for other custom fields, but for this custom field it's just not working. 

0 votes
Alexey Matveev
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.
January 23, 2019

Hello,

It should work. I guess, something is wrong with the Jira instance. Have a look in the logs.

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2019

Thanks for the response, but I don't see anything in the logs.

Suggest an answer

Log in or Sign up to answer