Trying to script a data change event to update a dataset in a List

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

	Arguments:
		tag: The source tag object. A read-only wrapper for obtaining tag
		     properties.
		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.
	"""
	
	print "currentValue", currentValue.value
	window = system.gui.getWindow("OPCUA Monitor 1 Root")
	dataset = window.getComponentForPath("Root Container.MessageLog").data

	#dataset = event.source.getComponent("MessageLog").data
	pdataset = system.dataset.toPyDataSet(dataset)
	pdataset.addRow([currentValue])
	dataset = system.dataset.toDataSet(pdataset)
	window.getComponentForPath("Root Container.MessageLog").data = dataset
	#event.source.getComponent("MessageLog").data = dataset

Even though system.gui autocompletes it is telling me that “gui” does not exist.

Error executing script.
Traceback (most recent call last):
  File "<tagevent:valueChanged>", line 4, in valueChanged
AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'gui'

I am at a loss as to why I cannot do this.

Tags are gateway-scoped “global” resources that do not belong to any project.

You can’t reference any client-scoped scripting functions or try to interact with a Vision window like this.

How do I update a dataset based upon a tag value change? Can datasets be in the same scope as tags?

It looks to me like you just need to bind your table’s data property to that tag value.

You are right. I needed to bind a memory dataset tag to my List. Now I am trying to update the memory dataset by adding rows. Each time the value changes I need to add a row. So it acts like a message log:

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

	Arguments:
		tag: The source tag object. A read-only wrapper for obtaining tag
		     properties.
		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.
	"""
	
	tlist = ["MessageLogDataset"]
	
	tags = system.tag.readBlocking(tlist)
	print tags
	print currentValue.value
	for tag in tags:
		dataset = tag.value
		break
		
	system.dataset.addRow(dataset,0,[currentValue.value]) 
	system.tag.writeBlocking(tlist, [dataset])

I don’t get any errors, it does not update the dataset tag (even though the tag initiating this event does update), I never see the print values. The only time I see info is when it tells me there is an issue with the script in the tag properties window. How do i get tag scope print messages to show in the console?

Kind of out on a limb here, but perhaps the fact that “tag” is used as a parameter in the function definition and you use it as the loop variable, things aren’t working as expected?

All of the dataset manipulation functions return a new dataset; they don't modify the existing one. You need to write the new dataset value you get from calling this function.

I was 99% there! Thank you for that last 1%! Which usually takes 99% time.

Also your print statements made in gateway-scoped code will end up in the wrapper.log files where the gateway is installed.

You can get statements into the logs page on the gateway by using system.util.getLogger: system.util.getLogger - Ignition User Manual 8.1 - Ignition Documentation

You won’t get gateway-scoped logging of any kind in your client or designer.