Run named query and move data to OPC tags

Hi, I have a project where I need to run a named query then from the columns grab the data and assign it to OPC tags.
So far I tried to run the query from the scrip console but it return "none". So it isn't running the query?

I have the script attached to a tag and it runs on change.

parameters = { Sequence : currentValue }
#Query call and store results
qresult = system.db.runNamedQuery(Vision_OC, parameters)
#Place Results in Tags
[.]VIN = qresult.getValueAt(1, 1)

At this moment the error I'm getting is that I can't assign the result to a string. Any help would be appreciated.

This is not valid syntax in a script. You will need to use system.tag.writeBlocking().

Don't forget to use quotes around the string constants in your script.

So I looked into your recommendation and I have no errors on the script at least that Ignition would let me know but when I run it my tags don't change value, went to the gateway logs and this is what is shows:

com.inductiveautomation.ignition.common.script.JythonExecException: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Project name required for script execution: the Gateway Scripting Project is not set.

My Code now looks as follow:

parameters = { "Sequence" : currentValue }
#Query call and store results
qresult = system.db.runNamedQuery("Vision_OC", parameters)
#Place Results in Tags
paths =["[default]Folder/Folder/Tag","[default]Folder/Folder/Tag"]
valueA = qresult.getValueAt(1,1)
valueB = qresult.getValueAt(1,15)
values = [valueA, valueB]
system.tag.writeBlocking(paths, values)

{ Please use the "Preformatted text" editor button instead of the block quote button for code snippets. }

system.db.runNamedQuery() has two different sets of arguments, based on the calling scope. You are trying to use the syntax for Designer or Vision Client scope, but are apparently calling from a tag event (gateway scope).

Tags do not belong to projects, so many such calls from gateway scope must specify a project name (where to find the named query).

First of apologies, the preformatted test was hidden in the cog, now I know. So it is still not running but now with a different error.

com.inductiveautomation.ignition.common.script.JythonExecException: java.lang.Exception: java.lang.Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the ****** value '******' to data type ******.

So now there is an issue with the data type? So I checked tag is set to string but it is only numbers, if I type the numbers it will still recognize it as a string correct? could that be the data type? the column 1 and 15 of the query both are string and the example for the sytem.tag.writeBlocking() shows inserting the values to a list.

parameters = { "Sequence" : currentValue }
	#Query call and store results
	qresult = system.db.runNamedQuery("CognexVisionSystem", "Vision_OC", parameters)	
	#Place Results in Tags
	paths =["[default]CognexEOLInspection/AD01_Cognex/VIN","[default]CognexEOLInspection/AD01_Cognex/Logo"]
	valueA = qresult.getValueAt(1,1)
	valueB = qresult.getValueAt(1,15)
	values = [valueA, valueB]
	system.tag.writeBlocking(paths, values)type or paste code here

currentValue is qualified values,

The currentValue and previousValue arguments are qualified values: objects that contain a value, timestamp, and quality. This means that to get to the value of the currentValue, your script would need to access currentValue.value

1 Like