# Dynamic flex repeater instances JSON

**URL:** <https://forum.inductiveautomation.com/t/dynamic-flex-repeater-instances-json/53601>\
**Category:** Ignition\
**Created:** [December 1, 2021, 2:39am UTC](https://forum.inductiveautomation.com/t/dynamic-flex-repeater-instances-json/53601 "2021-12-01T02:39:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [December 1, 2021, 2:39am UTC](https://forum.inductiveautomation.com/t/dynamic-flex-repeater-instances-json/53601/1 "2021-12-01T02:39:24Z")

</div>

Hello all,  
I would like to bind the instance parameter of a flex repeater to a named query where I return a number.  
In this example, whatever value returns from the named query should be the new value on my instances.

In my example, value 4 is returned from the named query if I put the format as json I get this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/f/df4f0bbfe2ad92f315da0c476313733a1f7f0a78.png)

which is not correct and it has to be:

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

How should I transform this to be ale to get the instances correctly?

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [December 1, 2021, 3:21am UTC](https://forum.inductiveautomation.com/t/dynamic-flex-repeater-instances-json/53601/2 "2021-12-01T03:21:33Z")

</div>

Found the solution:

You have to change the return format to a scalar for the named query and then return the transform script:

```auto
	dict={ "instanceStyle": {
			  		"classes": ""
			  		},
		"instancePosition": {}
			}
	list=[]
	for i in range(value):	
		list.append(dict)
	return list

```

---

<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:** [December 1, 2021, 3:25pm UTC](https://forum.inductiveautomation.com/t/dynamic-flex-repeater-instances-json/53601/3 "2021-12-01T15:25:01Z")

</div>

Note that as a general rule you should not name variables in Python `list`, `dict`, etc, as they shadow the builtin function names.

You can rewrite your transform to use a list comprehension to be a bit cleaner (in my opinion, anyway) and avoid the shadowing issue:

```python
	return [
		{
			"instanceStyle": {
		  		"classes": ""
	  		},
			"instancePosition": {}
		}
		for i in xrange(value)
	]

```

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [December 1, 2021, 3:41pm UTC](https://forum.inductiveautomation.com/t/dynamic-flex-repeater-instances-json/53601/4 "2021-12-01T15:41:04Z")

</div>

Thank you very much, Paul for the great information.
