When creating a scripted field, I'm pulling information from an external database in my script. It seems relatively simple, and it seems to work once, but then it will never work again. Everything depends on issue.reporterId, but when that reporter changes, my fields don't seem to update. I've tried disabling the cache, but that wouldn't help. Any thoughts on this script or some updates or settings I'm missing?
Also, my logging doesn't appear to work, probably because I'm bad at this!
import groovy.sql.Sql
import java.sql.Driver
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
enableCache = {-> false}
log.info("Disabled Cache")
def userManager = ComponentAccessor.getUserManager()
// All for the SQL stuff.
def driver = Class.forName('com.microsoft.sqlserver.jdbc.SQLServerDriver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "xxxxx")
props.setProperty("password", "xxxxxxx")
def conn = driver.connect("jdbc:sqlserver://SQLBOX:1433;instance=CP;DatabaseName=xxxxxxx", props)
def sql = new Sql(conn)
log.info("Connected to Database")
log.info(issue.reporterId)
try {
def wow = sql.firstRow("SELECT t.ManagerPartyID, t.Segment AS segment, t.CostCenter AS costcenter, (SELECT s.NetworkLogin from MasterData.NOV.Employee as s WHERE s.PartyID = t.ManagerPartyID) as Manager FROM MasterData.NOV.Employee as t WHERE NetworkLogin = ${issue.reporterId}")
return userManager.getUserByKey(wow.Manager)
} finally {
sql.close()
conn.close()
}I've tested the SQL query and these work when querying manually. It's also occurring with fields that don't rely on SQL.
Any input is greatly appreciated!