For loop to create instances, getting nested within itself error

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

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

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

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.

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

2 Likes

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

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?

{'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'}]}]}}

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.

1 Like

Well... I'll be... :joy:

He's right in assuming this. Jokes on me, I have "hourly template" and "hourbyhour" and got them confused. :man_facepalming:

Now I'm getting another type of error in the view that says
image

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

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 :upside_down_face:

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

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