# DataSet in Tag Event Script giving me errors

**URL:** <https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 29, 2020, 9:18pm UTC](https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313 "2020-04-29T21:18:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 29, 2020, 9:18pm UTC](https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313/1 "2020-04-29T21:18:43Z")

</div>

I have been trying to figure this out for a couple hours with no luck. I am attempting to write a ‘Value Change’ ‘Tag Event Script’ to read values from a Data Set. I’m using 8.0.12

A simplified version of my code attempt is below. I can’t read a DataSet from a query tag and write an indexed value to another tag without getting an error. Realistically I’ll need to loop through the dataset to extract some data. But, I’m trying to minimize the code here, I need help getting past the easy stuff. I keep getting errors when trying to access values in the data set.

* * *

If I do this, it works fine. The dataset shows up in the newTag and no gateway errors!

```auto
rType= system.tag.read("[.]../QueryTag").value #read tag
pyrType =system.dataset.toPyDataSet(rType) #make it a pyDataSet
rTypeCount = pyrType.getRowCount() #get number of rows

system.tag.write("[.]newTag",pyrType) #write data set to a newTag

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c90adfa2730dcbdec7aa69eb56b39a9a82af8074.png)

* * *

If I do this, it writes the correct value (“1”) to the tag but I still get an error “Row index 0 out of range”

```auto
system.tag.write("[.]newTag",pyrType[0][0])

```

* * *

And, if I change the row index, it writes the correct value (“6”) to the tag but I still get an error “Row index 5 out of range”

```auto
system.tag.write("[.]newTag",pyrType[5][0])

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/ac0fb1a67e9f63abfcb877c020da3186db0e20ac.png)

* * *

Even this retrieves the correct value (“Set2”) but I still get an error “Row index 5 out of range”

```auto
system.tag.write("[.]newTag",pyrType[5][1])

```

* * *

Also, if I try this, I get an error saying the column ‘IgnitionKeyWord’ Column doesn’t exist. But it DOES return the correct value and write it to the tag.

```auto
system.tag.write("[.]newTag",pyrType.getValueAt(0,'IgnitionKeyWord'))

```

* * *

But if I run this, It return a 1 (as expected) with no errors.

```auto
system.tag.write("[.]newTag",pyrType.getColumnIndex(0,'IgnitionKeyWord'))

```

If I try the ‘getValueAt(row,col)’ function I get the same behavior with a slightly different error “ArrayIndexOutOfBoundsException”

I am so confused, I don’t even know what to ask. Why would I be getting gateway errors if it’s retrieving the correct values from the dataset? Am I missing something. I’m planning to loop through the data set and extract values from it so they can be written to other tags. I’ll have a lot of errors in the gateway log if just ignore them.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 30, 2020, 1:05am UTC](https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313/2 "2020-04-30T01:05:06Z")

</div>

Try checking for the number of rows to be greater than 0 before processing the dataset.

Since it’s on a query, I suspect the tag is getting cleared before the updated dataset is being written. That means two events for the price of one.

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 30, 2020, 3:54pm UTC](https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313/3 "2020-04-30T15:54:56Z")

</div>

OK…Hear me out…  
I think I know what’s causing the errors I’m seeing but I don’t understand why.  
As I said, when I was calling the `system.tag.write("tag",dataset[][])` function it does write the value to the tag but I get an error in the gateway logs.

Yesterday I was reading the initial dataset tag using a relative tag path  
`system.tag.read("[.]../QueryTag").value`

I just tried to read the tag with an absolute path and I get NO errors.  
`system.tag.read("[default]QueryTag").value`

Why would using the relative vs actual tag path make a difference and cause gateway errors?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 30, 2020, 6:57pm UTC](https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313/4 "2020-04-30T18:57:35Z")

</div>

I had some time this afternoon to look at this. Honestly, I haven’t been able to replicate the issue using relative paths. 😕

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 30, 2020, 7:43pm UTC](https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313/5 "2020-04-30T19:43:37Z")

</div>

That’s crazy. I appreciate you spending some time on this. I’ll start a new blank project tonight and try to replicate with some simple tags

I don’t know if I was clear on my tags but the tag event script is from a tag within a UDT and I’m reading a dataset from another UDT instance.

I’ll try to post a copy of my test project here.

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 30, 2020, 8:54pm UTC](https://forum.inductiveautomation.com/t/dataset-in-tag-event-script-giving-me-errors/34313/6 "2020-04-30T20:54:25Z")

</div>

This has been driving me nuts so I just went ahead and made a new project with a new set of tags to demonstrate. I tried to attach it here. It’s a backup of the project and the tags used. The ‘Value Changed’ ‘tag event script’ is implemented in the BatchNumber tag of the Device UDT  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/df18314d9fec9d596a0853a97f4909920d603e83.png)

While creating this test project, I have learned that the error is only occurring initially. What I mean is if I open the tag event script editor, make changes, click ‘commit’, and then click apply (in the ‘tag editor’ window) the script automatically fires and I get the errors. This was the problem I have been seeing and it does also occur in this new test project with test tags.

However, the error does not seem to persist. Once the script is in place and it is fired from the tag actually changing the errors do not occur. In the test example, changing the BatchNumber parameter of the ‘Room’ tag (an instance of the UDT Room) causes the ‘Device#’ BatchNumber tags to update.

So… It seems that this is not a major issue after all. I did however spend a lot of time try to avoid having the errors occur.

I’m not sure why the errors occur initially but it did lead me down a deep rabbit hole and it’s a little miss leading. I don’t know if it should be classified as a bug or if there’s a good explanation for the behavior.

Thank you @JordanCClark for taking some time to look at this. Hopefully the attached is enough to put together a test project if someone wants to confirm. (I’ve tested on both 8.0.11 and 8.0.12, which are basically identical)

[tags.json](https://forum.inductiveautomation.com/uploads/short-url/5BA0XkAebMXwsEU8C083mNqCbaq.json) (274 Bytes) [TestTagEvent\_2020-04-30\_1559.zip](https://forum.inductiveautomation.com/uploads/short-url/4VR8DiVotbD2lGOnvA01WHUQF8Q.zip) (2.0 KB)
