Error with System.db.runPrepUpdate

Hi!

I'm trying to insert data into SQL with an event (on mouse click) that runs a simple script:

def runAction(self, event):
	
	ValorDataHora = system.date.now()
	ValorArea = self.getSibling("CoordinateContainer").custom.Area
	ValorMatricula = self.getSibling("CoordinateContainer").custom.Matricula
	ValorPrioridade = self.getSibling("CoordinateContainer").custom.Prioridade
	ValorEtiqueta = self.getSibling("CoordinateContainer").custom.Etiqueta
	ValorSAP = self.getSibling("CoordinateContainer").custom.SAP
	ValorTipoProblema = self.getSibling("CoordinateContainer").custom.TipoProblema
	ValorOutros = self.getSibling("CoordinateContainer").custom.Outros
	ValorDescricao = self.getSibling("CoordinateContainer").custom.DescProblema
	ValorSolucao = self.getSibling("CoordinateContainer").custom.DesSolucao
	ValorPeriodo = self.getSibling("CoordinateContainer").custom.PeridoRealizacao
	
	
	ValorDataHora1 = str(ValorDataHora)
	ValorArea1 = str(ValorArea)
	ValorMatricula1 = str(ValorMatricula)
	ValorPrioridade1 = str(ValorPrioridade)
	ValorEtiqueta1 = str (ValorEtiqueta)
	ValorSAP1 = str (ValorSAP)
	ValorTipoProblema1 = str (ValorTipoProblema)
	ValorOutros1 = str (ValorOutros)
	ValorDescricao1 = str (ValorDescricao)
	ValorSolucao1 = str (ValorSolucao)
	ValorPeriodo1 = str (ValorPeriodo)
	
	query = "INSERT INTO survey ( datahora, area, matricula, prioridade, etiqueta, sap, tipoproblema, outros, descricao, solucao, periodorealizacao) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
	System.db.runPrepUpdate(query,[ValorDataHora1,ValorArea1,ValorMatricula1,ValorPrioridade1,ValorEtiqueta1,ValorSAP1,ValorTipoProblema1,ValorOutros1,ValorDescricao1,ValorSolucao1,ValorPeriodo1],"SQL")

But when i press the button with this event i get the following error:

Error running action 'dom.onClick' on LandingPageView/6_Resumo@D/root/Button: Traceback (most recent call last): File "function:runAction", line 30, in runAction NameError: global name 'System' is not defined

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:runAction", line 30, in runAction
NameError: global name 'System' is not defined

caused by org.python.core.PyException

Traceback (most recent call last):
File "function:runAction", line 30, in runAction
NameError: global name 'System' is not defined

Ignition v8.1.42 (b2024061810)
Java: Azul Systems, Inc. 17.0.11

i was looking on Add Data to Database Video at Inductive University

Where the same System.db.runPrepUpdate was used but I'm still stuck with this error.

If anyone has any ideas or solutions for this case, i would appreciate!

Capitalization matters.
system, not System.

For some other advice...

Don't do this (specifically). Dates sent to your database should stay dates, and be translated into the appropriate data for your column by the JDBC driver. By casting a date time to string before sending it to the database, you are irrevocably losing information.

Also, don't do this (generally).
If you ever find yourself repeating the same operation many times in a row in a programming context... don't.
You can easily refactor this to operate on a list (e.g with Python's builtin map function), but there's more to do before we get there.

You're using the root container to keep track of custom properties - this is great - but the repeated reference to a single property can be avoided with a simple rebinding.
Between that, and some other refactoring, you can rewrite this whole script to reduce duplication and opportunities for typos significantly:

def runAction(self, event):
    custom = self.getSibling("CoordinateContainer").custom
    parameters = [
        system.date.now(),  # datahora
        custom.Area,
        custom.Matricula,
        custom.Prioridade,
        custom.Etiqueta,
        custom.SAP,
        custom.TipoProblema,
        custom.Outros,
        custom.DescProblema,
        custom.DesSolucao,
        custom.PeridoRealizacao
    ]
    query = """
    INSERT INTO survey (datahora,
                        area,
                        matricula,
                        prioridade,
                        etiqueta,
                        sap,
                        tipoproblema,
                        outros,
                        descricao,
                        solucao,
                        periodorealizacao)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    """
    system.db.runPrepUpdate(query, parameters, "SQL")