I am doing some API work using the Web Dev module. When data posts to my endpoint it is written to a few memory tags. I have a tag change script on one of the memory tags to write to another memory tag in a hierarchy model according to the value in data posted. To do this I have to do a lookup in a database first.
This is the error I get in the Diagnostics pane in the Tag Editor:
Error executing script.
Traceback (most recent call last):
File "<tagevent:valueChanged>", line 29, in valueChanged
UPDATE oee.vin_location
SET exit_timestamp = ?
WHERE vin_id = ?::UUID
, [2022-07-29 09:13:58, d36a13a0-64c0-4489-87b4-71f274538831], , , false, false)
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:258)
at jdk.internal.reflect.GeneratedMethodAccessor112.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(
UPDATE oee.vin_location
SET exit_timestamp = ?
WHERE vin_id = ?::UUID
, [2022-07-29 09:13:58, d36a13a0-64c0-4489-87b4-71f274538831], , , false, false)
This is my code in Value Changed section in Tag Editor:
data = system.tag.readBlocking("[default]EOL_Testing/Camera_Data")[0].value
vin = system.tag.readBlocking("[default]EOL_Testing/Another_Test_Post")[0].value
stationIn = system.tag.readBlocking("[default]EOL_Testing/Test_Post")[0].value
line = system.tag.readBlocking("[default]EOL_Testing/Line_Test")[0].value
metadataValue = system.util.jsonEncode({"sos_name": stationIn})
lookupVin = system.db.runNamedQuery("SCADA_Map","EOL/LookupVIN", {"lookup_vin": vin})
lookupStation = system.db.runNamedQuery("SCADA_Map","EOL/GetShortName", {"sos": metadataValue})
vinId = system.db.runNamedQuery("SCADA_Map","EOL/GetVinId", {"lookup": vin})
vinLocationId = system.db.runNamedQuery("SCADA_Map","EOL/VinLocationId", {"lookup_id": vinId})
date = system.date.format(system.date.now(),"YYYY-MM-dd HH:mm:ss")
model = ""
color = ""
if currentValue.value == lookupVin and currentValue.value != previousValue.value:
if vinId == vinLocationId:
if previousValue.value:
prodTagPath = "[OEE]Normal 1/End of Line/%s/%s/ProdOEE/%s" %(line, lookupStation, "ObjectID")
objIdValue = system.tag.readBlocking(prodTagPath)[0].value
query = """
UPDATE oee.vin_location
SET exit_timestamp = ?
WHERE vin_id = ?::UUID
"""
args = [date, vinId]
system.db.runPrepUpdate(query, args)
if currentValue.value:
insert_statement = """
INSERT INTO oee.vin_location (vin_id, entry_timestamp, object_id)
VALUES (?::UUID, ?, ?::UUID)
"""
values = [vinLocationId, date, objIdValue]
system.db.runPrepUpdate(insert_statement, values)
writeVin = "[OEE]Normal 1/End of Line/%s/%s/ProdOEE/%s" %(line, lookupStation, "VIN")
system.tag.writeBlocking(writeVin, currentValue.value)
Edited this post:
I solved the previous question about the Named Query. I had to cast the value to make sure it matches using the ::JSONB.
Now I have this new error with regards to line 29. I made sure to cast in my Named Queries as well depending on value whether it is ::JSONB or ::UUID. Now I dont why I am still getting this error.
Any help with this is much appreciated. Thanks