# Writing a value from a dataset tag

**URL:** <https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587>\
**Category:** Ignition\
**Created:** [October 24, 2022, 10:08am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587 "2022-10-24T10:08:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 24, 2022, 10:08am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/1 "2022-10-24T10:08:14Z")

</div>

Hello, I would like to update (add a row) to my tag dataset.

I'am using this fonction :` system.tag.writeBlocking(self.view.params.tagPath, self.view.params.listZone)` When I try use this function, the old value on the dataset is droped

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/2/42e3f94c651f7e74c2ac99b208bb19061aece839.png)

---

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [October 24, 2022, 10:51am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/2 "2022-10-24T10:51:11Z")

</div>

The function requires a list of tag paths and a list of values. Try:  
`system.tag.writeBlocking([self.view.params.tagPath], [self.view.params.listZone])`

---

<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:** [October 24, 2022, 11:13am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/3 "2022-10-24T11:13:02Z")

</div>

Use [system.dataset.addRows()](https://docs.inductiveautomation.com/display/DOC81/system.dataset.addRows) first, then write back to the tag.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 24, 2022, 11:16am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/4 "2022-10-24T11:16:35Z")

</div>

Do you really need a dataset for just one column ?

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 24, 2022, 11:50am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/5 "2022-10-24T11:50:57Z")

</div>

yes for one column

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 24, 2022, 11:53am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/6 "2022-10-24T11:53:01Z")

</div>

I can see there's only one column, my question was: do you NEED a dataset ? Wouldn't an array be enough ?

---

<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:** [October 24, 2022, 11:59am UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/7 "2022-10-24T11:59:12Z")

</div>

> [@pascal.fragnoud](#):
>
> Do you really need a dataset for just one column ?

No, could very easily be an array type tag. To each their own.

> [@sebastien\_ng](#):
>
> I'am using this fonction :` system.tag.writeBlocking(self.view.params.tagPath, self.view.params.listZone)` When I try use this function, the old value on the dataset is droped

Follow these steps.

1.) Read in the tag  
2.) Add the row  
3.) Write out the new Value.

Be sure that you write the entire dataset to the tag value, as opposed to just a single row, column pair.

```python
#read in the dataset from the tag.
ds = system.tag.readBlocking([self.view.params.tagPath])[0].value
#add the row to the dataset
ds = system.dataset.addRows(ds,[[self.view.params.listZone]])
#write out the new value
system.tag.writeBlocking([self.view.params.tagPath],[ds])

```

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 24, 2022, 12:33pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/8 "2022-10-24T12:33:24Z")

</div>

thank you, it work

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 24, 2022, 12:34pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/9 "2022-10-24T12:34:48Z")

</div>

I needed a dataset, not array

---

<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:** [October 24, 2022, 12:48pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/10 "2022-10-24T12:48:02Z")

</div>

A dataset, with 1 column is just an array with extra baggage. Are you sure you _needed_ a dataset?

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 24, 2022, 1:24pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/12 "2022-10-24T13:24:52Z")

</div>

yes I'am sure I need dataset. there is the solution

```auto
#Update Device dataset
	#read in the dataset from the tag.
	DevicePath = self.view.params.tagPath
	dsDevice = system.tag.readBlocking([DevicePath])[0].value
	#add the row to the dataset
	dsDevice = system.dataset.addRows(dsDevice,[[self.view.params.idZone]])
	#write out the new value
	system.tag.writeBlocking([self.view.params.tagPath],[dsDevice])
	
	#update zone Dataset
	#add info for zone
	zonePath = "[tagXX]Site"+str(self.view.params.idSite)+"/Building"+str(self.view.params.idBuilding)+"/Zone/Zone"+str(self.view.params.idZone)+"/listDevice"
	dsZone = system.tag.readBlocking([zonePath])[0].value
	dsZone = system.dataset.addRows(dsZone,[[self.view.params.idDevice]])

```

```
system.tag.writeBlocking([zonePath],[dsZone])

```

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [October 24, 2022, 1:30pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/13 "2022-10-24T13:30:17Z")

</div>

Now, When I add a value, if the value exists on the dataset, I would like to avoid redundancy of values ​​in the dataset.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/0/8066ac1dcf0984ca74831019e744a69519f4c4c0.png)

---

<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:** [October 24, 2022, 1:47pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-from-a-dataset-tag/65587/14 "2022-10-24T13:47:21Z")

</div>

Nothing in that code, indicates the need for a dataset. Everything you're doing could be easily accomplished with a List (a.k.a array). The dataset is only adding overhead. Oh well, you do you.

To prevent duplicates in the column you will need to loop through the column and verify that value doesn't exist. The easiest way to do that is to convert the column to a list.

```python
#Update Device dataset
	#read in the dataset from the tag.
	DevicePath = self.view.params.tagPath
	dsDevice = system.tag.readBlocking([DevicePath])[0].value
	#verify if value already exists, if not then add row and write value
	if not self.view.params.idZone in ds.getColumnAsList(0):
		#add the row to the dataset
		dsDevice = system.dataset.addRows(dsDevice,[[self.view.params.idZone]])
		#write out the new value
		system.tag.writeBlocking([self.view.params.tagPath],[dsDevice])
	
	#update zone Dataset
	#add info for zone
	#use string.format
	zonePath = "[tagXX]Site{0}/Building{1}/Zone/Zone{2}/listDevice".format(self.view.params.idSite,self.view.params.idBuilding,self.view.params.idZone)
	dsZone = system.tag.readBlocking([zonePath])[0].value
	dsZone = system.dataset.addRows(dsZone,[[self.view.params.idDevice]])

```
