# Dynamic Dataset creation for template repeater Vision

**URL:** <https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [June 8, 2023, 9:10pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800 "2023-06-08T21:10:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [June 8, 2023, 9:10pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/1 "2023-06-08T21:10:34Z")

</div>

Looking for best way to create dynamic dataset for a template repeater

dataset to be based on variables ValueA, ValueB, startid, stopid (all these are values from screen objects/parameters

such that

colnames : Name / type / ID  
row1 : =valueA / =valueB / =startid  
row2 =valueA / =valueB / =startid+1  
row3 =valueA / =valueB / =startid+2  
row4 =valueA / =valueB / =startid+3  
...  
until startid=stopid

---

<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:** [June 8, 2023, 9:17pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/2 "2023-06-08T21:17:19Z")

</div>

This would be a pretty simple list comprehension paired with `system.dataset.toDataSet`, I imagine.

```python

valueA = "ValueA"
valueB = "ValueB"
startId = 10
stopId = 20

headers = ["Name", "Type", "ID"]
data = [
  [valueA, valueB, index]
  for index in range(startId, stopId)
]

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

```

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [June 8, 2023, 9:19pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/3 "2023-06-08T21:19:30Z")

</div>

ok, what I was generally thinking, but was hoping there was some solution that i could do in expression instead of using scripting.

Thanks

---

<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:** [June 8, 2023, 9:21pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/4 "2023-06-08T21:21:20Z")

</div>

Nope, no ability to loop in expressions, so you'll have to use some amount of scripting.

---

<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 8, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/5 "2023-06-08T21:29:57Z")

</div>

> [@paul-griffith](#):
>
> no ability to loop in expressions

Funny you should say that.

I had to stay home today, so my thumb twiddling has been off in that sort of left field....

---

<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 14, 2023, 3:55pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/6 "2023-06-14T15:55:59Z")

</div>

Now for a ~~working example~~ {Edit: `unionAll` changed, see below}, using the latest Simulation Aids:

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-simulation-aids-v2/74934/3):
>
> So I was poking around and realized I missed a major feature: a substitute for python's range() functions. And while at it, I factored out some common code so that where() and orderBy() could handle and return sequences instead of just datasets. Of the four iterators, now only the selectStart() function requires and returns a dataset. forEach() still only returns a list, but can accept datasets, lists, arrays, and single integers (for range behavior). Here ya go: For Ignition v8.1+ only: v…

As an expression function (use a reference to a `startid` tag instead of `50`):

```auto
unionAll(
	asList("Name", "Type", "ID"),
	asList("str", "str", "i"),
	forEach(
		15,
		"ValueA",
		"ValueB",
		50+it()
	)
)

```

Yields this dataset:

```auto
"#NAMES"
"Name","Type","ID"
"#TYPES"
"str","str","O"
"#ROWS","15"
"ValueA","ValueB","50"
"ValueA","ValueB","51"
"ValueA","ValueB","52"
"ValueA","ValueB","53"
"ValueA","ValueB","54"
"ValueA","ValueB","55"
"ValueA","ValueB","56"
"ValueA","ValueB","57"
"ValueA","ValueB","58"
"ValueA","ValueB","59"
"ValueA","ValueB","60"
"ValueA","ValueB","61"
"ValueA","ValueB","62"
"ValueA","ValueB","63"
"ValueA","ValueB","64"

```

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [December 19, 2023, 5:22pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/7 "2023-12-19T17:22:34Z")

</div>

I copied your example into my project, but it returns this error.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/9/19fd0f49e74a69289caa24b4168856e0363128c0.png)

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [December 19, 2023, 5:25pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/8 "2023-12-19T17:25:18Z")

</div>

post the expression that is generating this

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [December 19, 2023, 5:26pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/9 "2023-12-19T17:26:15Z")

</div>

```auto
unionAll(
	asList("Name", "Type", "ID"),
	asList("str", "str", "i"),
	forEach(
		15,
		"ValueA",
		"ValueB",
		50+it()
	)
)

```

---

<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:** [December 19, 2023, 5:29pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/10 "2023-12-19T17:29:59Z")

</div>

I made a breaking change to the arguments for the `unionAll` expression function after this post. That expression now needs to be:

```auto
unionAll(
	asMap(
		"Name", "str",
		"Type", "str",
		"ID", "i"
	),
	forEach(
		15,
		"ValueA",
		"ValueB",
		50+it()
	)
)

```

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [December 19, 2023, 5:38pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/11 "2023-12-19T17:38:35Z")

</div>

There seems to be a bug with the unionAll that doesn't allow for just one column. I can create a data set with multiple columns, but if I try to create a dataset with just one column, it gives me this error.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/b/fb5b01f293fac717973e3883ac9195142e709f2d.png)

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [December 19, 2023, 5:39pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/12 "2023-12-19T17:39:14Z")

</div>

This is the expression

```auto
unionAll(
	asMap(
		"Value","i"
	),
	forEach(
		5,
		50+it()
	)
)

```

---

<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:** [December 19, 2023, 5:49pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/13 "2023-12-19T17:49:01Z")

</div>

`unionAll()` expects to receive **lists** of **rows** , that is, lists of lists. `forEach()` returns a simple list when only one iterating expressing is given, but a list of lists when more than one is supplied. To fix your single-column case, wrap `50+it()` inside another `asList()`.

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [December 19, 2023, 6:10pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/14 "2023-12-19T18:10:00Z")

</div>

@pturmel, I'm trying to use `tag()` as part of the `forEach()` function, like so:

```auto
unionAll(
	asMap(
		"Name","str",
		"JP Color","i"
	),
	forEach(
		len({Flowline.Sources}),
		{Flowline.Sources}[it(),"Name"],
		tag({Flowline.Sources}[it(),"Name"]+"_Color")
	)
)

```

However, the expression doesn't seem to like the `it()` as part of the tagPath, it returns -1 for every row of the dataset. If I put a constant in instead of `it()`, then it returns proper values from a tag.

---

<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:** [December 19, 2023, 6:13pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/15 "2023-12-19T18:13:57Z")

</div>

The `tag()` function is not compatible with iteration. Along with any other functions that have any asynchronous retriggering or polling behavior. (This includes any function that needs a _context_, like `runScript()`, `objectScript()`, and `view()`.)

If you need to read dynamic lists of tags, use the module's `tags()` function (outside of any iteration).

`tags()` works best if the list of tagpaths to read is constructed in a separate binding. Since you are using Vision, that would need to be a dataset custom property.

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [December 19, 2023, 6:16pm UTC](https://forum.inductiveautomation.com/t/dynamic-dataset-creation-for-template-repeater-vision/74800/16 "2023-12-19T18:16:14Z")

</div>

I will give that a try.
