# Can I use system.tag.read for a dataset

**URL:** <https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 22, 2022, 7:57pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081 "2022-06-22T19:57:06Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 22, 2022, 7:57pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/1 "2022-06-22T19:57:06Z")

</div>

Example:

```auto
ValveDataset = system.tag.read("System1/Project1/HOA/Valves")
    for rowRead in ValveDataset:
        CRvalveTo[rowRead['id']] = rowRead['description']

```

or do datasets need to be read differently.

---

<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:** [June 22, 2022, 7:59pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/2 "2022-06-22T19:59:18Z")

</div>

`system.tag.read()` returns a Qualified Value, so you need to reference the `value` attribute.

```auto
ValveDataset = system.tag.read("System1/Project1/HOA/Valves").value
for rowRead in ValveDataset:
    CRvalveTo[rowRead['id']] = rowRead['description']

```

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 22, 2022, 8:34pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/3 "2022-06-22T20:34:03Z")

</div>

For anyone who comes by in the future, on V8.0 or later:

You should use [system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking). `system.tag.read` is depreciated.

readBlocking returns a list of Qualified Values, so it’ll look like:  
`ValveDataset = system.tag.readBlocking([tagPath])[0].value`

I don’t know what type of dataset the readBlocking will return, a regular dataset or a pydataset. The regular dataset isn’t iterable (I don’t think), so you’ll need to convert a regular dataset if readBlocking doesn’t return a pydataset by default. You can convert using:

`pydata = system.dataset.toPyDataset(ValveDataset)`

Then you can iterate over pydata as above.

---

<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:** [June 22, 2022, 8:35pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/4 "2022-06-22T20:35:55Z")

</div>

> [@zacht](#):
>
> You should use [system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking). `system.tag.read` is depreciated.

Their system is Ignition 7.8, so `system.tag.read()` is correct.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 22, 2022, 8:40pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/5 "2022-06-22T20:40:20Z")

</div>

How did you figure this out? I don’t see a version tag.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 22, 2022, 8:40pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/6 "2022-06-22T20:40:50Z")

</div>

@lrose is familiar with my sobbing on here. lol @zacht

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 22, 2022, 9:22pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/7 "2022-06-22T21:22:35Z")

</div>

> [@zacht](#):
>
> depreciated

Heh. (Spelling) Deprecated just means it isn't documented for new users. IA is unlikely to actually break these any time soon.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 22, 2022, 9:26pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/8 "2022-06-22T21:26:40Z")

</div>

TIL. I didn’t know there was a defined difference.

---

<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:** [June 23, 2022, 11:45am UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/9 "2022-06-23T11:45:10Z")

</div>

> [@zacht](#):
>
> I don’t know what type of dataset the readBlocking will return, a regular dataset or a pydataset.

It is a standard dataset. I failed to correct that part of the code.

This:

```auto
ValveDataset = system.tag.read("System1/Project1/HOA/Valves").value
for rowRead in range(ValveDataset.rowCount):
    CRvalveTo[ValveDataset.getValueAt(rowRead,'id')] = ValveDataset.getValueAt(rowRead,'description')

```

or

```auto
ValveDataset = system.dataset.toPyDataset(system.tag.read("System1/Project1/HOA/Valves").value)
for rowRead in ValveDataset:
    CRvalveTo[rowRead['id']] = rowRead['description']

```

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 8, 2022, 7:54pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/10 "2022-08-08T19:54:47Z")

</div>

@lrose I’m getting a an error when trying to use the snippets above. Bottom one gives keyerror, top one gives eof error.

---

<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:** [August 8, 2022, 8:03pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/11 "2022-08-08T20:03:54Z")

</div>

> [@andrews](#):
>
> Bottom one gives keyerror, top one gives eof error.

The bottom script by itself, can not give a key error, because you are not referencing a value in a dictionary. You'll need to provide the rest of the script.

With the top one, you are not reading from a file, so an `eof` doesn't really make since.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 8, 2022, 8:11pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/12 "2022-08-08T20:11:48Z")

</div>

@lrose here it is

```auto
# Gets Valve
valve = event.source.parent.getComponent('Label').text
# List of vales with multiple locations. 
ValveMultLocs =["AB_211220","XV_211102","AB_210720","XV_210402","XV_210502","XV_210102","XV_211002","XV_210603","XV_210803","XV_210903"]
if valve in ValveMultLocs:
    # Get Tank Number
    GetTank = event.source.parent.parent.Page
    # Read the selected Transfer To for apropriate tank
    TransferTo = system.tag.read("System1/Project1/Tank Details/"+GetTank+"/TransferTo").value
    # validate transfer
    message = "Do you want to open" + GetTank + "to" + TransferTo
    system.gui.messageBox(message)
    # ask user to verify transfer location
    UserInputTransfer = system.gui.showTouchscreenKeyboard("Verify Transfer Location")
    if UserInputTransfer == TransferTo:
        message = GetTank + " will now open to " + TransferTo 
        system.gui.box(message)
        value = event.source.Setvalue
        event.source.parent.Set_tag_state = value
    else:
        system.gui.messageBox("Transfer input did not match Tank Details selection.")
else:
    #Dictionary to place valve location dataset in.
    CRvalveTo = {}
    #Dataset of valve locations
    ValveDataset = system.dataset.toPyDataSet(system.tag.read("System1/Project1/HOA/Valves").value)
    #Puts dataset into a dict
    for rowRead in ValveDataset:
        CRvalveTo[rowRead['id']] = rowRead['description']
    #Gets transfer location
    valveCrossx = CRvalveTo[valve]
    UserInputTransfere = system.gui.showTouchscreenKeyboard("Verify Transfer Location")
    if UserInputTransfere == valveCrossx:
        message = valve + " will now open to " + valveCrossx 
        system.gui.messageBox(message)
        value = event.source.Setvalue
        event.source.parent.Set_tag_state = value
    else:
        system.gui.messageBox("Transfer input did not match Tank Details selection.")

```

---

<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:** [August 8, 2022, 8:31pm UTC](https://forum.inductiveautomation.com/t/can-i-use-system-tag-read-for-a-dataset/61081/13 "2022-08-08T20:31:33Z")

</div>

You would only get a key error on this line:

```auto
valveCrossx = CRvalveTo[valve]

```

This means that the value the of `valve` (so `event.source.parent.getComponent('Label').text`) is not a value in the ‘id’ column of the dataset. Key’s are case sensitive so, insure that the value of the label matches exactly the value and case of the id you’re looking for.
