# For loop to create instances, getting nested within itself error

**URL:** <https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 9, 2024, 9:42am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146 "2024-05-09T09:42:00Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshwa\_Bachelder](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Joshwa\_Bachelder](https://forum.inductiveautomation.com/u/Joshwa_Bachelder)\
**Post date:** [May 9, 2024, 9:42am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/1 "2024-05-09T09:42:00Z")

</div>

Hi guys,

Still new to some of this. I'm having issues when using a for loop to drive the creation of instances for a template.

The code is creating the correct amount of instances and in the side panel under the instances section, I see all of the data I'm needing to supply my template with, but it's erroring and maybe it's just me being a noob, not sure.

The code is below

```python
base_URL = system.tag.readBlocking('[default]RestfulEndpointBaseURL')[0].value
	endpoint_URL = base_URL + self.parent.getChild("HeaderContainer").getChild("MachineName").props.text
	result = system.net.httpClient().get(endpoint_URL)
	isCurrentHour = ''
	if result.statusCode == 200:
		print result.json
		views = []
		for metric in result.json["content"]["metrics"]:
			for obj in metric["HourlyKPI"]:
				views.append({
				"currentHour":isCurrentHour,
				"DT":obj["kpi"]["downtime"],
				"Hour":obj["hour"],
				"OEE":obj["kpi"]["oee"],
				"PT":obj["kpi"]["plannedDt"],
				"RT":obj["kpi"]["runTime"],
				"RU":obj["kpi"]["rejects"],
				"UL":obj["kpi"]["u.lost"],
				"UP":obj["kpi"]["u.prod"],
				"UT":obj["kpi"]["u.theorical"]})
			return views

```

 ![nestedviewerror](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/d/7dee9daec17bc050a37dca009dd0c09fb42bf1ce.png)

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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 9, 2024, 10:07am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/2 "2024-05-09T10:07:40Z")

</div>

I haven't quite figured out how it's supposed to work, but is your last line, `return views`, indented one too many?

---

<div class="post-metadata">

**Author:** ![Joshwa\_Bachelder](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Joshwa\_Bachelder](https://forum.inductiveautomation.com/u/Joshwa_Bachelder)\
**Post date:** [May 9, 2024, 10:18am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/3 "2024-05-09T10:18:28Z")

</div>

I tried moving it but it seems to just give me the same amount of instances and the same error regardless of where I put the indent.

---

<div class="post-metadata">

**Author:** ![Ujwal\_Wankhede](https://avatars.discourse-cdn.com/v4/letter/u/4af34b/32.png) [@Ujwal\_Wankhede](https://forum.inductiveautomation.com/u/Ujwal_Wankhede)\
**Post date:** [May 9, 2024, 10:26am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/4 "2024-05-09T10:26:55Z")

</div>

Are you certain that you're not referencing the same view you're currently in with 'props.path'?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 9, 2024, 10:35am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/5 "2024-05-09T10:35:57Z")

</div>

Post the (nicely formatted) result.json so we can replicate.

---

<div class="post-metadata">

**Author:** ![Joshwa\_Bachelder](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Joshwa\_Bachelder](https://forum.inductiveautomation.com/u/Joshwa_Bachelder)\
**Post date:** [May 9, 2024, 10:40am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/6 "2024-05-09T10:40:00Z")

</div>

How could I be referencing it twice if it's not in the code I posted? Is there some other way to accidentally do this?

---

<div class="post-metadata">

**Author:** ![Joshwa\_Bachelder](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Joshwa\_Bachelder](https://forum.inductiveautomation.com/u/Joshwa_Bachelder)\
**Post date:** [May 9, 2024, 10:43am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/7 "2024-05-09T10:43:08Z")

</div>

```python
{'content': {'route': u'', 'metrics': [{'line': u'B-Mat', 'lastUpdate': u'05-09 06:42:43', 'HourlyKPI': [{'kpi': {'color': u'1', 'plannedDt': u'9.15', 'u.theorical': u'480', 'oee': u'68.96 %', 'downtime': u'0.0', 'rejects': u'0', 'u.prod': u'331', 'runTime': u'20.85', 'u.lost': u'149'}, 'hour': u'09 - 05'}, {'kpi': {'color': u'0', 'plannedDt': u'0.0', 'u.theorical': u'683', 'oee': u'98.68 %', 'downtime': u'0.0', 'rejects': u'0', 'u.prod': u'674', 'runTime': u'42.72', 'u.lost': u'9'}, 'hour': u'09 - 06'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 07'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 08'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 09'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 10'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 11'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 12'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 13'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 14'}, {'kpi': {'color': u'', 'plannedDt': u'', 'u.theorical': u'', 'oee': u'', 'downtime': u'', 'rejects': u'', 'u.prod': u'', 'runTime': u'', 'u.lost': u''}, 'hour': u'09 - 15'}]}]}}

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 9, 2024, 10:44am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/8 "2024-05-09T10:44:06Z")

</div>

> [@Joshwa\_Bachelder](#):
>
> How could I be referencing it twice if it's not in the code I posted?

Ujwal is suggesting the possibility that you have selected the wrong view in the `props.path` dropdown. It will list the view you are working on so it won't stop you choosing it and causing recursion.

---

<div class="post-metadata">

**Author:** ![Joshwa\_Bachelder](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Joshwa\_Bachelder](https://forum.inductiveautomation.com/u/Joshwa_Bachelder)\
**Post date:** [May 9, 2024, 10:46am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/9 "2024-05-09T10:46:57Z")

</div>

Well... I'll be... 😂

He's right in assuming this. Jokes on me, I have "hourly template" and "hourbyhour" and got them confused. 🤦‍♂️

Now I'm getting another type of error in the view that says  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/d/8de29d01dce91c937a937f3e310a05f8e1e7418b.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 9, 2024, 10:50am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/10 "2024-05-09T10:50:22Z")

</div>

You haven't shown us the sub-view yet. Copy the AY\_Label object and paste it in here.

---

<div class="post-metadata">

**Author:** ![Joshwa\_Bachelder](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Joshwa\_Bachelder](https://forum.inductiveautomation.com/u/Joshwa_Bachelder)\
**Post date:** [May 9, 2024, 10:52am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/11 "2024-05-09T10:52:37Z")

</div>

I got it. I had double {} around my tag within the binding of the background color property. Man copying and pasting from other projects sure throws you into a whirl. Sorry guys. Hope this was a fun thread to tackle this morning 🙃

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 9, 2024, 10:53am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/12 "2024-05-09T10:53:29Z")

</div>

Good work. Don't forget to check that `return views` indentation.

---

<div class="post-metadata">

**Author:** ![Joshwa\_Bachelder](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Joshwa\_Bachelder](https://forum.inductiveautomation.com/u/Joshwa_Bachelder)\
**Post date:** [May 9, 2024, 11:41am UTC](https://forum.inductiveautomation.com/t/for-loop-to-create-instances-getting-nested-within-itself-error/90146/13 "2024-05-09T11:41:55Z")

</div>

Appreciate you guys! Thank you so much. It's the little things.
