Access one piece of Data from Query Tag

So here is the code I have so far....

Product_Code_Query = system.tag.read("[default]Product code Query Tag.value")
Product_Code_Compare = system.tag.read("[default]Product_Code_Compare_Tag.value")

print Product_Code_Query
print Product_Code_Compare

if (Product_Code_Query != Product_Code_Compare):
	system.tag.write("[default]Product_Code_Compare_Tag",Product_Code_Query.value)
	CurrentCount = system.tag.read("[default]L2_Former_Run_Day_Count")
	system.tag.write("[default]L2_Former_Run_Day_Count", (CurrentCount.value + 1))

I think it will do what I need it to but the issue is I cant seem to be able to access the specific data of the dataset.
The "Product code Query Tag" is an SQL query tag that pulls the last entry into a database containing a date and a product code. The product code isnt run but once every few days so i am trying to keep a tally of how many days a particular product code is run and therefore be able to alarm on x amount of days to trigger a PM
When I run the script I cant seem to pull out just the day and time to compare to see if it is a new day and increase the counter.
Here is the output

>>> 
[Dataset [1R ? 2C], Good, Fri Dec 16 16:14:42 EST 2022]
[Dataset [1R ? 2C], Good, Fri Dec 16 16:14:58 EST 2022]
2
2
>>>

If I create a null value the values are different and it will copy the data over and increase the counter but it is comapring the entire dataset not the date. I have tried a million ways to parse just the date to compare but no luck!!
Here is the data in the dataset I am querying
image
Please Help I dont have any more hair to pull!!

If you're dealing with a dataset, you need to extract the particular value you care about, by providing a row index and column name or index:

Product_Code_Query_DS = system.tag.read("[default]Product code Query Tag.value").value
Product_Code_Compare_DS = system.tag.read("[default]Product_Code_Compare_Tag.value").value

Product_Code_Query = Product_Code_Query_DS.getValueAt(0, "Date")
Product_Code_Compare = Product_Code_Compare_DS.getValueAt(0, "Date")

print Product_Code_Query_DS
print Product_Code_Query

print Product_Code_Compare_DS
print Product_Code_Compare

if Product_Code_Query != Product_Code_Compare:
	system.tag.write("[default]Product_Code_Compare_Tag",Product_Code_Query)
	CurrentCount = system.tag.read("[default]L2_Former_Run_Day_Count").value
	system.tag.write("[default]L2_Former_Run_Day_Count", CurrentCount + 1)

See the Datasets reference page in the manual.

That what I figured but I Tried that before also.
Here is the result of that code on my end

Traceback (most recent call last):
File "", line 4, in
AttributeError: 'com.inductiveautomation.ignition.common.sqltags.Ba' object has no attribute 'getValueAt'

What was executed
Product_Code_Query_DS = system.tag.read("[default]Product code Query Tag.value")
Product_Code_Compare_DS = system.tag.read("[default]Product_Code_Compare_Tag.value")

Product_Code_Query = Product_Code_Query_DS.getValueAt(0, 0)
Product_Code_Compare = Product_Code_Compare_DS.getValueAt(0, 0)

print Product_Code_Query
print Product_Code_Query_DS

print Product_Code_Compare
print Product_Code_Compare_DS

if (Product_Code_Query != Product_Code_Compare):
system.tag.write("[default]Product_Code_Compare_Tag",Product_Code_Query.value)
CurrentCount = system.tag.read("[default]L2_Former_Run_Day_Count")
system.tag.write("[default]L2_Former_Run_Day_Count", (CurrentCount.value + 1))

You are putting the .value inside the tagpath. Where it is redundant. The tag read call is still going to give you a QualifiedValue object, to which you can then apply .value to get the actual tag value.

Tried that also
It doesnt give me the data though only gives me the Dataset? It also doesnt see them as equal and increments which is what led me to try and just isolate the date since it would be the only thing that changes.
Here is the output I get now

Dataset [1R ? 2C]
[Dataset [1R ? 2C], Good, Fri Dec 16 16:14:42 EST 2022]
Dataset [1R ? 2C]
[Dataset [1R ? 2C], Good, Fri Dec 16 18:04:32 EST 2022]
2
2

And the code

Product_Code_Query_DS = system.tag.read("[default]Product code Query Tag")
Product_Code_Compare_DS = system.tag.read("[default]Product_Code_Compare_Tag")

Product_Code_Query = Product_Code_Query_DS.value
Product_Code_Compare = Product_Code_Compare_DS.value

print Product_Code_Query
print Product_Code_Query_DS

print Product_Code_Compare
print Product_Code_Compare_DS

if (Product_Code_Query != Product_Code_Compare):
system.tag.write("[default]Product_Code_Compare_Tag",Product_Code_Query)
CurrentCount = system.tag.read("[default]L2_Former_Run_Day_Count")
system.tag.write("[default]L2_Former_Run_Day_Count", (CurrentCount.value + 1))

You need to do both things, as I did in my code above.

Use .value to go from the BasicQualifiedValue returned by system.tag.read to a Dataset.
Then use .getValueAt(row, column) to get a single scalar value out of that dataset.
You must do both.

1 Like

{ When you paste code or error tracebacks, please use the "Preformatted Text" button (</>) to make them look right. Help us help you. }

AH HA!!!!!
I didnt scroll over and see the .value at the end of the first 2 lines!
IT WORKED THANK YOU!!!!!!

1 Like