Hello
I have an issue with the script for a button.
I am creating a form to capture data and save it to a Data Base, but I have an error with the script for the button. Already tested the query and it works.
This is my code:
Grab the Data from the components added to the window.
Tecnico = event.source.parent.getComponent('Numeric Text Field')
Fecha = event.source.parent.getComponent('Popup Calendar')
Comentario = event.source.parent.getComponent('Text Area')
Spare_Parts = event.source.parent.getComponent('Text Area 1')
Tiempo = event.source.parent.getComponent('Numeric Text Field 2')
Resultado = event.source.parent.getComponent('Numeric Text Field 1')
call to the Named Query, inserting the parameters.
caused by GatewayException: Error serializing parameters.
caused by NotSerializableException: com.inductiveautomation.ignition.common.gui.border.FieldBorder
The problem is you’re sending the objects themselves as parameters to the query. Try something like Comentario.text, Spare_Parts.text, Tiempo.intValue etc.
I changed my code trying to follow the user manual Inserting data into database, but can’t find what I am doing wrong.
This is how I changed it:
> # Grab the Data from the components added to the window.
> Tecnico = event.source.parent.getComponent('Numeric Text Field').IntegerValue
> Fecha = event.source.parent.getComponent('Popup Calendar').date
> Comentario = event.source.parent.getComponent('Text Area').Text
> Spare_Parts = event.source.parent.getComponent('Text Area 1').Text
> Tiempo = event.source.parent.getComponent('Numeric Text Field 2').FloatValue
> Resultado = event.source.parent.getComponent('Numeric Text Field 1').IntegerValue
>
> # A call to the Named Query, inserting the parameters.
> system.db.runNamedQuery("Insert data",
> {"Tecnico":Tecnico, "Fecha":Fecha, "Comentario":Comentario, "Spare_Parts":Spare_Parts, "Tiempo":Tiempo, "Resultado":Resultado})
Python is case-sensitive - those ‘Text’ ones should just be ‘text’. ‘IntegerValue’ should be ‘intValue’, things like that. In the property editor you can hover over the name of the property on the left and it will tell you its scripting name. Make sure to use the right capitalization with those and you should be good.
Also, just a note for the code snippet you put in there - use three backticks like ```, before and then again after the code you paste. It formats it better.
Just use the Insert Property Reference in the upper right hand corner of the scripting window until you get the hang of it. The icon looks like a chain link