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
Thanks all for the reply, it's now working fine after reindex, and removing the listener and adding it again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
I tried the approach of issueManager plus the explicit reindex code but that didn't work as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would definitely expect Approach 4 (reindex the issue) to be necessary
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
It should work. I guess, something is wrong with the Jira instance. Have a look in the logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the response, but I don't see anything in the logs.
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.