I am trying to set up a Scriptrunner script to access external pgsql database. I am using the script console to attempt to execute the following code:
import groovy.sql.Sql
import java.sql.Driver
import com.atlassian.jira.component.ComponentAccessor
def customFieldObjects = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)
def db = [url:'jdbc:postgresql:localhost:testdb', user:'', password:'', driver:'org.postgresql.jdbc.JDBCDriver']
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
def NameVM1 = customFieldObjects.findByName("NameVM")
def CPU1= customFieldObjects.findByName("CPU")
def RAM1 = customFieldObjects.findByName("RAM")
def HDD1 = customFieldObjects.findByName("HDD")
try {
sql.execute ('INSERT INTO customers (namevm, cpu, ram, hdd) values (?, ?.(), ?, ?)', NameVM1, CPU1, RAM1, HDD1)
} finally {
sql.close()
}
But my scipt failed
2023-09-01 13:56:59,458 WARN [sql.Sql]: Failed to execute: INSERT INTO customers hdd values ? because: Can't infer the SQL type to use for an instance of com.atlassian.jira.issue.fields.ImmutableCustomField. Use setObject() with an explicit Types value to specify the type to use.
2023-09-01 13:56:59,462 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'ucbadmin'. View here: http://10.8.123.220:8080/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=PTSD%3A+Service+Request+Fulfilment+workflow+for+JIRA+Service+Desk&descriptorTab=postfunctions&workflowTransition=1&highlight=1 org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of com.atlassian.jira.issue.fields.ImmutableCustomField. Use setObject() with an explicit Types value to specify the type to use. at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1051) at Script139.run(Script139.groovy:18)
I would be grateful if you could help me find the error.