Hi,
Jira version 7.2.6
Script runner 1.5.4
I have one script listener to "issue updated" event to update the summery based on the custom fields selection. It is working fine but when I am searching in jql search then summary still showing old one. When I open the issue then summary showing fine so I suspected that issue is not indexing after the update hence did the project indexing manually. After the index of project "summary" showing fine.
Can anyone please help me what should I add in my script listener to reindex automatically when there is update on issue.
Here is the code
package com.custom
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
class SetDefaultFields extends AbstractIssueEventListener {
Category log = Category.getInstance(SetDefaultFields.class)
SetDefaultFields () {
log.setLevel(org.apache.log4j.Level.DEBUG)
}
@Override
void issueUpdated(IssueEvent event) {
// Get custom field value
log.debug "Event300: Start UpdateIssue.groovy"
MutableIssue issue = event.issue as MutableIssue
def cfVal
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def IssueManager issueManager = ComponentAccessor.issueManager
if( issue.getIssueType().getName().equals("Application")){ //changed to this after migration to 7.x
def cf1 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Division")
def cfDiv = issue.getCustomFieldValue(cf1)
def cf2 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Name / Sub Type")
Map cfList = issue.getCustomFieldValue(cf2) as Map
if (cfList) {
String first = cfList.get(null)
String second = cfList.get("1")
if (second == null ){
second = "All"
}
// log.debug("First - second: $first - $second")
issue.summary = first + " - " + second + " - " + cfDiv
}
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH ,false)
Thanks
Om.
Om friend:
If you see your last line:
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH ,false)
The most important bit being:
EventDispatchOption.DO_NOT_DISPATCH
You are not dispatching an issue update event. Therefore, your JIRA isn't reindexing, that's why your value in your JQL appears as the old one, because you haven't "updated" the database yet.
If you want your listener to update your values the moment it fires, you need to update it with:
EventDispatchOption.ISSUE_UPDATED
That should reindex your issue but be careful. Since if this gets triggered very often it could considerably slow down your JIRA instance performance considerably.
If this solved your doubt, please upvote and accept my answer, since this will let other users know that this question has been answered.
Cheers!
Dyelamos
Hi Dyelamos,
As per your comment, I have one doubt. Reindex happen only modified issue alone right not the entire jira instance indexing right?
_------------
That should reindex your issue but be careful. Since if this gets triggered very often it could considerably slow down your JIRA instance performance considerably.
---------------------------
Thanks,
Om
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Think about Re indexing as follows:
You have a Bookshelf of 1000 books.
You a bookshelf in which you order them by Author. This is your "Index"
And once awhile someone tells you that one was incorrect.
That means that you need to look at your entire list, find the correct book, change the information in your list, physically take the book out, and move it to the correct place.
Now imagine that it isn't only 1 bookshelf, but as many as the custom and system fields that JIRA has.
Now imagine that it isn't 1000 books, but 2 million JIRA issues.
If you re index 400 times in a row. Your librarian might loose his mind right?
Same principle. Yes, you are technically re indexing 1 issue, but what you are re indexing against is the real problem. If you have a small instance, it won't matter too much. But if you have a big instance and you are reindexing like a maniac, that will take a huge processing time, and you will notice a performance impact.
I hope this helped you out.
If you have anymore questions I'd be happy to help.
Cheers
DYelamos
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.