# Template Repeater not loading templates on the first window open

**URL:** <https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [March 30, 2023, 4:41am UTC](https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811 "2023-03-30T04:41:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [March 30, 2023, 4:41am UTC](https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811/1 "2023-03-30T04:41:59Z")

</div>

I have two windows in my project, Window A and Window B. In Window A, I have a button that opens Window B and passes a parameter value to it. In Window B, I have a Template Repeater (Template Repeater 1) with a text field inside it, and I want to display the parameter value in the text field.

However, I encountered an issue where the first time I click the button in Window A to open Window B, I get an "IndexError: index out of range: 0" error. To debug this issue, I added the following script in the WindowOpened event of Window B:

```auto
templateRepeater = get_component('Template Repeater 1')
templates = templateRepeater.getLoadedTemplates()
system.gui.messageBox(len(templates), "templates number")

```

I observed that when I first open Window B, the length of templates is zero, which is likely causing the IndexError. However, when I close Window B and open it again, the length of templates is now 1, and the parameter is displayed correctly in the text field.

I would like to get some guidance on how to resolve this issue, so the Template Repeater loads the templates correctly when Window B is opened for the first time.

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [March 30, 2023, 11:18am UTC](https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811/2 "2023-03-30T11:18:33Z")

</div>

To troubleshoot it since the issue doesn't seems obvious at first sight to me, i woud try and add a print statement to the script that opens Window B that print outs the parameter being passed to see if it's actually being passed. Then i would also try and add a label component or something similar (depending on what is the paremeter being passed) on Window B and bind it's text to the parameter that should've been received to see if actually shows up on the first time you open the window.  
If you dedice to follow these steps, please show us the outcome.

---

<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:** [March 30, 2023, 12:13pm UTC](https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811/3 "2023-03-30T12:13:13Z")

</div>

Sounds like a design flaw. You are **pushing** the parameter to the template. Instead, supply the parameter in the template repeater's dataset, allowing the template to **pull** the value as it initializes.

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [April 13, 2023, 2:55am UTC](https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811/4 "2023-04-13T02:55:54Z")

</div>

In order to debug this issue and eliminate other interferences, I created two new windows: windowA and windowB. WindowA contains a button, and clicking it will close WindowA and open windowB. Inside windowB, there is a label and a Template Repeater, which also contains a label. I need to set the initial text of these two labels to test\_initial\_String = "Set default value success".

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/3/23a09ac0c2de81a06d87e5ad67e79b0536d40cbb.png)

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

When I click the button in windowA for the first time to open windowB, I receive an error.

WindowB opened script

```auto
test_initial_String = "Set default value success"

system.gui.getParentWindow(event).getComponentForPath('Root Container.Label').text = test_initial_String

repeater = system.gui.getParentWindow(event).getComponentForPath('Root Container.Template Repeater')
#Store the list of templates in another variable
templateList = repeater.getLoadedTemplates()

print "============================================================= "
print "len(templateList)= " + str(len(templateList))
 
#Iterate through the list
for template in templateList:
    #find a component named "Label" in the instance,
    #and print the value of the text property 
   
    template.getComponent('Label').text = test_initial_String
    print "============================================================= "
    print "template.getComponent('Label').text : " + template.getComponent('Label').text
        

print "templateList[0] ================================================"
print templateList[0] 

```

Error:

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

Information I monitored from console:

```auto
============================================================= 
len(templateList)= 0
templateList[0] ================================================
10:55:02.466 [AWT-EventQueue-0] ERROR com.inductiveautomation.ignition.client.util.gui.ErrorUtil - <HTML>Error executing script for event:&nbsp;<code><b>visionWindowOpened</b></code><BR>on component:&nbsp;<code><b>TestWindowB</b></code>.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
  File "<event:visionWindowOpened>", line 26, in <module>
IndexError: index out of range: 0

	at org.python.core.Py.IndexError(Py.java:251)
	at org.python.core.SequenceIndexDelegate.checkIdxAndGetItem(SequenceIndexDelegate.java:63)
	at org.python.core.PySequence.seq ___getitem__ (PySequence.java:378)
	at org.python.core.PySequence. __getitem__ (PySequence.java:374)
	at org.python.pycode._pyx11.f$0(<event:visionWindowOpened>:26)
	at org.python.pycode._pyx11.call_function(<event:visionWindowOpened>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1687)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:800)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:299)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy42.visionWindowOpened(Unknown Source)
	at com.inductiveautomation.factorypmi.application.FPMIWindow.fireVisionWindowOpened(FPMIWindow.java:719)
	at com.inductiveautomation.factorypmi.application.VisionDesktop$RuntimeWindowOpener.openWindow(VisionDesktop.java:549)
	at com.inductiveautomation.factorypmi.application.VisionDesktop.openWindow(VisionDesktop.java:192)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.lambda$openWindowImpl$5(NavUtilities.java:393)
	at com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities.doGUIAction(WindowUtilities.java:808)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.openWindowImpl(NavUtilities.java:336)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.openWindow(NavUtilities.java:326)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilitiesDispatcher.openWindow(NavUtilitiesDispatcher.java:143)
	at jdk.internal.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:549)
	at org.python.core.PyObject. __call__ (PyObject.java:461)
	at org.python.core.PyObject. __call__ (PyObject.java:465)
	at org.python.pycode._pyx13.f$0(<event:actionPerformed>:7)
	at org.python.pycode._pyx13.call_function(<event:actionPerformed>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1687)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:800)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:299)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy40.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
	at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Container.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.python.core.PyException: IndexError: index out of range: 0
	... 74 common frames omitted

```

From message I print, it shows , **len(templateList)= 0**

And because of this, it does not execute, the loop , **for template in templateList**

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [April 13, 2023, 5:03pm UTC](https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811/5 "2023-04-13T17:03:03Z")

</div>

> [@Lina\_Su](#):
>
> WindowB opened script

Which event handler is it running under exactly?  
If it's "visionWindowOpened" maybe **this** is messing things up?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/5/35ec5fb95263438a33eea599f451c0b32b227902.png)  
What happens when you copy it to "internalFrameActivated"?  
Or even a clicked event on the template repeater(with some slight modifications to the paths) so you can be sure it's actually retrieving the data you need.

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [April 13, 2023, 5:58pm UTC](https://forum.inductiveautomation.com/t/template-repeater-not-loading-templates-on-the-first-window-open/71811/6 "2023-04-13T17:58:50Z")

</div>

I've tried what i said and it doesn't seem to work on any of the window opened scripts. It works if you place a similar script on a click event of any component of the window, probably because everything has been loaded by that point.  
What seems to be happening on your first post is that when you first open your window and the script fires, the templates aren't loaded yet, but when you close it, the window gets cached and the second time it opens, the templates are already loaded so your script works as intended.  
So, what @pturmel seems not only the best but the only way, which i believe would mean that you must pass your string parameter from Window A to B in the script, something like this:

```auto
#Assuming WindowB has a custom parameter in it's root container called "String2Pass"
window = system.nav.openWindow('Window/Main WindowB', {'String2Pass' : 'String sent from A to B'})
system.nav.centerWindow(window)

```

Then, along with the custom parameter on the root container, Window B will need a template repeater with it's "repeatBehavior" property set to dataset and it's templateParams property's dataset with a column that will correspond to the template property that will be passed to the templates, add a row and bind it's value to the root container's custom parameter, the dataset and it's binding will look something like this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/7/d73087235f4226793e4f6190c659383851e61b48.png)  
Then, don't forget that your template needs a Template Parameter with a name that matches the name of the column on the template repeater's dataset, like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/790207e39ea64791681a76c02f533124776bbbec.png)  
This will work as a demonstration only, so you'll have to change it's properties to match your project if you decide to use this method, but you can have more than one template property be dynamic and if you need a dynamic number of rows for the template repeater, you'll be better off removing the cell update binding and building yourself the rows of the dataset in a script.
