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

**URL:** <https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 21, 2021, 10:15pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892 "2021-04-21T22:15:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![frank.carney](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@frank.carney](https://forum.inductiveautomation.com/u/frank.carney)\
**Post date:** [April 21, 2021, 10:15pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/1 "2021-04-21T22:15:30Z")

</div>

```auto
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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 21, 2021, 10:19pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/2 "2021-04-21T22:19:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![frank.carney](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@frank.carney](https://forum.inductiveautomation.com/u/frank.carney)\
**Post date:** [April 21, 2021, 10:27pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/3 "2021-04-21T22:27:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 21, 2021, 10:44pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/4 "2021-04-21T22:44:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![frank.carney](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@frank.carney](https://forum.inductiveautomation.com/u/frank.carney)\
**Post date:** [April 22, 2021, 5:47pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/5 "2021-04-22T17:47:42Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 22, 2021, 5:55pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/6 "2021-04-22T17:55:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 22, 2021, 5:56pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/7 "2021-04-22T17:56:36Z")

</div>

> [@frank.carney](#):
>
> `system.dataset.addRow(dataset,0,[currentValue.value]) `

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.

---

<div class="post-metadata">

**Author:** ![frank.carney](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@frank.carney](https://forum.inductiveautomation.com/u/frank.carney)\
**Post date:** [April 22, 2021, 5:59pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/8 "2021-04-22T17:59:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 22, 2021, 6:01pm UTC](https://forum.inductiveautomation.com/t/trying-to-script-a-data-change-event-to-update-a-dataset-in-a-list/45892/9 "2021-04-22T18:01:06Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC81/system.util.getLogger)

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