# Script writing to a memory tag dataset

**URL:** <https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133>\
**Category:** Ignition\
**Created:** [February 21, 2023, 9:56pm UTC](https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133 "2023-02-21T21:56:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Heiting](https://avatars.discourse-cdn.com/v4/letter/n/8797f3/32.png) [@Nick\_Heiting](https://forum.inductiveautomation.com/u/Nick_Heiting)\
**Post date:** [February 21, 2023, 9:56pm UTC](https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133/1 "2023-02-21T21:56:23Z")

</div>

I have a series of tags that are reading values from a plc. I'd like to consolidate these tags into a single dataset with the intention of binding a table's data to the dataset for easy display.

My thought would be to have a Refresh button run a script like the following:  
Script was simplified from my original but gives the same error that is getting me stuck.

```auto
#get existing dataset
newData = system.tag.readBlocking(["[default]tagPath/existingDataset"])
#get data for new row
startTime = system.tag.readBlocking(["[default]tagPath/StartTime.value"])
endTime = system.tag.readBlocking(["[default]tagPath/EndTime.value"])
FT = system.tag.readBlocking(["[default]tagPath/FG.value"])

#create new row	
newRow = [startTime, endTime, FT]

print(newData)
#prints [[Dataset [0R ⅹ 3C], Good, Tue Feb 21 12:04:53 CST 2023 (1677002693877)]]

#following lines fails - TypeError: addRow(): 1st arg can't be coerced to com.inductiveautomation.ignition.common.Dataset
newData = system.dataset.addRow(newData, newRow)

#write back to the memory tag	
system.tag.write("[default]tagPath/existingDataSet", newData)

```

Before the second to last line the print(NewData) will output:  
[[Dataset [0R ⅹ 3C], Good, Tue Feb 21 12:04:53 CST 2023 (1677002693877)]]

On the following line (second to last line) the script fails with a error:  
"TypeError: addRow(): 1st arg can't be coerced to com.inductiveautomation.ignition.common.Dataset"

The examples I'm finding usually reference a tables existing prop.data and I could do that but would prefer to use a project script since I'll be re-utilizing this for multiple lines.

Am I misunderstanding something in my addRow command?

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [February 21, 2023, 10:13pm UTC](https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133/2 "2023-02-21T22:13:58Z")

</div>

Your tag reads are returning _Qualified Values_, which include a value, quality and timestamp, which you can see in your print statement. You need to use .value to get the value only.

```auto
newData = system.tag.readBlocking(["[default]tagPath/existingDataset"]).value

```

I can see that you have a .value in your start and end time tag paths, these should be outside the function as per above, not in the tag path.

You have also used system.tag.write which was deprecated after version 7.9 - I'm assuming you are on 8+ given you have used system.tag.readBlocking. You will want to change this to system.tag.writeBlocking

---

<div class="post-metadata">

**Author:** ![Alan\_Cannon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alan_cannon/32/31171_2.png) [@Alan\_Cannon](https://forum.inductiveautomation.com/u/Alan_Cannon)\
**Post date:** [February 21, 2023, 10:53pm UTC](https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133/3 "2023-02-21T22:53:16Z")

</div>

?  
[0].value  
v.s  
.value  
the read blocking returns the list[0=value,1=quality and 2=timestamp] correct? or can we just access .value as you indicated?

best

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 21, 2023, 11:08pm UTC](https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133/4 "2023-02-21T23:08:05Z")

</div>

`readBlocking` unconditionally returns a _list_ of _qualified value objects_.

So the correct syntax is `readBlocking(["path/to/tag"])[0].value` - get the first element of the list/index 0, and return its `value` property.

`readBlocking(["path/to/tag"])` and `readBlocking(["path/to/tag.value"])` are **exactly** equivalent; both will still have the same return value (a list of qualified values). We assume that if you don't specify a property underneath a tag, you wanted to read the value of it, as a shortcut.

As an aside, you basically never want to manually issue multiple read calls in a row from a script. **Always** try to collect your writes into as few calls as possible; it's significantly more efficient. E.G:

```python
tagPaths = [
	"[default]tagPath/existingDataset",
	"[default]tagPath/StartTime",
	"[default]tagPath/EndTime",
	"[default]tagPath/FG"
]
newData, startTime, endTime, FT = [qv.value for qv in system.tag.readBlocking(tagPaths)]

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [February 22, 2023, 2:33pm UTC](https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133/5 "2023-02-22T14:33:47Z")

</div>

Why not use a UDT?

---

<div class="post-metadata">

**Author:** ![Nick\_Heiting](https://avatars.discourse-cdn.com/v4/letter/n/8797f3/32.png) [@Nick\_Heiting](https://forum.inductiveautomation.com/u/Nick_Heiting)\
**Post date:** [February 22, 2023, 5:25pm UTC](https://forum.inductiveautomation.com/t/script-writing-to-a-memory-tag-dataset/70133/6 "2023-02-22T17:25:07Z")

</div>

Thanks all. That really helped to wrap my head around the variables and how they were interacting.

Got it working and optimized the multiple read/writes.
