[SOLVED] Tag Value Change script on memory tag (dataset type) not firing when dataset is updated

I have the following code on a tag value change script:

ds = currentValue.value
delRows = []
lim = system.tag.read("[.]data_limit").value #set to 100

if ds.getRowCount() > lim:
    for i in range(0, ds.getRowCount() - lim):
        delRows.append(i)
    currentValue.value = system.dataset.deleteRows(ds, delRows)

My dataset is going well above 100 a few rows at a time. It seems like the tag value change script is not firing for whatever reason. Is it possible that adding a row to a dataset is not triggering the change script?

You need to create a new dataset and write it back to the tag via system.tag.writeBlocking. You can’t just modify the dataset value you receive in the event or assign a new value back to the event object.

Isn't that what the last line is doing?

https://docs.inductiveautomation.com/display/DOC81/system.dataset.deleteRow

It's doing half of what I said, creating a new dataset, but you're just assigning it to a meaningless object and not writing it back.

-_-

I see. A misunderstanding on my part. I thought currentValue was somehow tied in to the tag.

No, it's just a copy of the tag's qualified value.

In some older versions modifications to "container" values like datasets or documents would mutate the actual value in the tag, but this was unintentional and fixed at some point.

1 Like

Now that makes a lot of sense because I thought this script was working at some point and then we upgraded to 8.1.17.

Well, it never would have worked the way you want, because part of the brokenness of that was that it didn't fire off event changes because nothing in the tag system knew about the value change.

1 Like
ds = currentValue.value
	delRows = []
	lim = system.tag.read("[.]data_limit").value
	
	if ds.getRowCount() > lim:
		for i in range(0, ds.getRowCount() - lim):
			delRows.append(i)
		new_ds = system.dataset.deleteRows(ds, delRows)
		system.tag.writeBlocking(["[.]data"], [new_ds])

Applied the new code and the problem was instantly resolved. Thanks!

1 Like