# Increment tag ID to create a DataSet

**URL:** <https://forum.inductiveautomation.com/t/increment-tag-id-to-create-a-dataset/19173>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 9, 2018, 2:12pm UTC](https://forum.inductiveautomation.com/t/increment-tag-id-to-create-a-dataset/19173 "2018-08-09T14:12:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anne-Marie.Coupal](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@Anne-Marie.Coupal](https://forum.inductiveautomation.com/u/Anne-Marie.Coupal)\
**Post date:** [August 9, 2018, 2:12pm UTC](https://forum.inductiveautomation.com/t/increment-tag-id-to-create-a-dataset/19173/1 "2018-08-09T14:12:59Z")

</div>

Hi,

I would like to know if there is a simple way to increment a tag ID. I am trying to read the value of different tags to create a dataset then, I want to put it in a table.

headers = [“Status”, “Permissive”]  
blankHeader = []  
blankData = []  
data = []  
i = 0

system.gui.getParentWindow(event).getComponentForPath(‘Root Container.Table’).data = system.dataset.toDataSet(blankHeader, blankData)

nb\_lignes = system.tag.read(“PLC\_DepocheusePolymere/Conv Alim Concasseur/Permissives/ConvAlimConcasseur\_PermissiveAbs\_INT”)

while ( i \< nb\_lignes.value ) :  
dataColonne1 = system.tag.read(“PLC\_DepocheusePolymere/Conv Alim Concasseur/Permissives/Absolute\*\*[i]\*\*”)  
dataColonne2 = system.tag.read(“PLC\_DepocheusePolymere/Conv Alim Concasseur/Permissives/HMI\_PermissiveAbs\_ConvAlimConcasseur\_ **i** \_”)  
data.append([dataColonne1.value, dataColonne2.value])  
**i = i + 1**

system.gui.getParentWindow(event).getComponentForPath(‘Root Container.Table’).data = system.dataset.toDataSet(headers, data)

Is there a simple way to do it?  
Thanks a lots

---

<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:** [August 9, 2018, 9:00pm UTC](https://forum.inductiveautomation.com/t/increment-tag-id-to-create-a-dataset/19173/2 "2018-08-09T21:00:58Z")

</div>

Hi!

As a side note, if you enclose your code with three back-quotes before and after, it makes thing a bit easier to read. 🙂

You pretty well hit on the simple way of doing it, but if there are many tags it may not be the most efficient way.

A couple of other differences you may notice:

- since all the tags are in the same folder, a path variable can save some typing, and can provide portability.
- same thing for the table component. It’s not a huge problem, since it’s only used once in this case, but it does put the name up at the top for easy editing.

Hope this helps!

```auto
# Loop through once, read each tag separately

basePath = 'PLC_DepocheusePolymere/Conv Alim Concasseur/Permissives/'
table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table')
headers = ["Status", "Permissive"]
data = []

nb_lignes = system.tag.read(basepath+"ConvAlimConcasseur_PermissiveAbs_INT")

for i in range(nb_lignes.value):
  dataColonne1 = system.tag.read(basepath+"Absolute[%s]" % str(i))
  dataColonne2 = system.tag.read(basepath+"HMI_PermissiveAbs_ConvAlimConcasseur_%s_" % str(i))
  data.append([dataColonne1.value, dataColonne2.value])

table.data = system.dataset.toDataSet(headers, data)

```

If you have a lost of tags to read, consider using two loops: one to create your tag lists and one create your dataset.

```auto
# Loop through twice, read all tags at same time

basePath = 'PLC_DepocheusePolymere/Conv Alim Concasseur/Permissives/'
table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table')
headers = ["Status", "Permissive"]
data = []
absoluteTags = []
concasseurTags = []

nb_lignes = system.tag.read(basepath+"ConvAlimConcasseur_PermissiveAbs_INT")

for i in range(nb_lignes.value):
  absoluteTags.append(basepath+"Absolute[%s]" % (str(i)))
  concasseurTags.append(basepath+"HMI_PermissiveAbs_ConvAlimConcasseur_%s_" % (str(i)))

dataColonne1 = system.tag.readAll(absoluteTags)
dataColonne2 = system.tag.readAll(concasseurTags)

for i in range(nb_lignes.value):
  data.append([dataColonne1[i].value, dataColonne2[i].value])

table.data = system.dataset.toDataSet(headers, data)

```

---

<div class="post-metadata">

**Author:** ![Anne-Marie.Coupal](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@Anne-Marie.Coupal](https://forum.inductiveautomation.com/u/Anne-Marie.Coupal)\
**Post date:** [August 10, 2018, 4:06pm UTC](https://forum.inductiveautomation.com/t/increment-tag-id-to-create-a-dataset/19173/3 "2018-08-10T16:06:27Z")

</div>

Wow thanks a lot for your help!
