Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted Field not re-indexed after updating/creating issue

Eryk Leniart
Contributor
February 16, 2018

Hi,

I have a problem with my Script Field from ScriptRunner add-on. What I'm trying to do is fix wrong behaviour with JIRA portfolio Team field which is not correctly displayed on JIRA widgets and Confluence pages.

So I came up with solution that I will implement Script Field with Team Name name which will be returning current issue Team name instead of id (which is native behaviour for Team field). To make it work I need to connect to JIRA database and retrieve Team name from table which maps Team ID to Team Name. Below is source code of my script field.

import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface

import java.sql.Connection

enableCache = {-> false}

def teamId = getCustomFieldValue("Team")

if (teamId){
def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default")

def sqlStmt = String.format('SELECT "TITLE" FROM public."AO_82B313_TEAM" WHERE "ID" = %s;', teamId)

Connection conn = ConnectionFactory.getConnection(helperName)
Sql sql = new Sql(conn)

def teamName

try {
sql.eachRow(sqlStmt) {
teamName = it.TITLE
}
}
finally {
sql.close()
}

return String.valueOf(teamName)
}

return null


The problem is that sometimes this scripted field (Team Name) is not re-indexed after creating or updating issue, so JQL query displays incorrect number of issues i.e.

"Team" = 1 (1100 issues)
"Team Name" = "abc" (1050 issues)

After re-indexing whole instance (or specific project) these two clauses return the same number, but after that new issues are sometimes corrupted.

I think the problem is that while I'm retrieving data from database issue is already reindexing.

Any ideas how can I workaround this?

Thanks!

0 answers

Suggest an answer

Log in or Sign up to answer