How to take first row of a querry tag and write it to a similar memory dataset tag? on Value Changed script

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	Fired whenever the current value changes in value or quality.

		tag: The source tag object. A read-only wrapper for obtaining tag
		tagPath: The full path to the tag (String)
		previousValue: The previous value. This is a "qualified value", so it
		               has value, quality, and timestamp properties.
		currentValue: The current value. This is a "qualified value", so it has
		              value, quality, and timestamp properties.
		initialChange: A boolean flag indicating whether this event is due to
		               the first execution or initial subscription.
		missedEvents: A flag indicating that some events have been skipped due
		              to event overflow.
	var ="[.]/Querry")
	data = system.dataset.toPyDataSet(var.value)
	system.tag.write("[.]/Data/Lots", data)

So i need to read the querry tag and append only the first row of memory tag.

	qset ="[.]/Querry")
	dset ="[.]/Data/Lots")
	qdata = system.dataset.toPyDataSet(qset.value)
	ddata = system.dataset.toPyDataSet(dset.value)
	system.tag.write("[.]/Data/Lots", qdata)
	fr = []
	for col in range(qdata.getColumnCount()):
		fr.append(qdata.getValueAt(0, col))
	print fr 

returns what i need kinda i guess the l is for long datatype:

[u'19D03297B013', 16L, 2019-10-24 18:41:45.0, 2019-10-24 18:43:10.0, 1970-01-01 00:01:25.0, u'038']

now how to go about writing that to just the first row of the data/lots tag?

If you just want the first row from the source tag, the simplest way is to construct another dataset that has the other rows deleted. Ignition can do that with system.dataset.deleteRows(). Something like this:

qs ="[.]Querry").value
ds = system.dataset.deleteRows(qs, range(1, qs.rowCount))
system.tag.write("[.]/Data/Lots", ds)

That’s it. Note that datasets are supposed to be immutable – you don’t modify them, you make new ones with the change(s) you want. Also, you don’t need a PyDataset unless you wish to loop through its rows with a simple for loop.

If i wrote that to a separate tag.

then wanted to take that dataset with one row and update the target tags first row.

Or maybe I am way off.

I have a large querry that gets dumped into this source tag.

Then writing to the mem tag for a table. That they are going to do work against. (selecting the rows and making print jobs and writing back to a diff db)

always on row[1] and below.

Am i going the wrong way about this?

I think so. Your mem tag is going to get clobbered every time the original query runs. Editing tables in place is tricky with bindings. Consider just showing the source query to your users in a read-only table. (With the query right there on the table, not a tag.) When they pick a row other than the first, enable the buttons and/or editable fields for their task. When that task is done, script an update query on the source table (marking that row done or whatever), then fire a refresh on the table’s sql binding so that row will disappear.

If the task involves editing some of that row data, do it one at a time, and consider using the raw/dirty technique described here:

{ What’s with the two 'r’s in query, btw? }

hahahaha it’s a typo in over 50 UDTs and I am to scared to change it… Its been driving me wild. quer

especially when it’s right next to the little query.

It’s only between you and me tho. As I am our only eng.

Thanks for the help!

1 Like