# Accessing templates from another template

**URL:** <https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390>\
**Category:** Ignition\
**Created:** [April 29, 2014, 11:16pm UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390 "2014-04-29T23:16:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdeavers](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rdeavers](https://forum.inductiveautomation.com/u/rdeavers)\
**Post date:** [April 29, 2014, 11:16pm UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/1 "2014-04-29T23:16:48Z")

</div>

I have many instances of one template on my form. Each instance represents an hour of a shift with data such as completed parts. I am trying to keep a running total of completed parts from each hour. So I would like to access the previous hour (template instance) to add it to the current hour.

I have a template parameter for the parts completed that hour. My project crashes as soon as I try to access that parameter, or any other parameter, from another template instance.

Thank you.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 30, 2014, 12:04am UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/2 "2014-04-30T00:04:28Z")

</div>

Hi rdeavers,

How are you accessing the template parameter? Scripting? Property binding? Expression binding?

What version of Ignition are you using?

If you can create a simple version of the template with the problem and then export it and upload it to this forum topic then I will check it out and if there is a bug then the template can be sent to IA and the bug can be fixed.

Best,  
Nick Mudge  
Ignition Consultant  
[nickmudge.info](http://nickmudge.info)

---

<div class="post-metadata">

**Author:** ![rdeavers](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rdeavers](https://forum.inductiveautomation.com/u/rdeavers)\
**Post date:** [April 30, 2014, 12:06am UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/3 "2014-04-30T00:06:54Z")

</div>

Hello,

I’m accessing the template from a property change script My Ignition version is 7.6.4  
Creating a simple one will take some time but I’ll work on it and post it.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 30, 2014, 12:13am UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/4 "2014-04-30T00:13:51Z")

</div>

Okay, you could post your propertyChange script here. That might be enough to determine the problem.

---

<div class="post-metadata">

**Author:** ![rdeavers](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rdeavers](https://forum.inductiveautomation.com/u/rdeavers)\
**Post date:** [April 30, 2014, 12:25am UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/5 "2014-04-30T00:25:57Z")

</div>

Here is a simple version of my script:

`
if event.source.instanceName:
	if event.source.instanceName == 'testTemplate1':
		event.source.thisValue = '1'
	elif event.source.instanceName == 'testTemplate2':
		event.source.thisValue = event.source.parent.getComponent('testTemplate1').thisValue + '1'
	elif event.source.instanceName == 'testTemplate3':
		event.source.thisValue = event.source.parent.getComponent('testTemplate2').thisValue + '1'`

My error is this:  
Traceback (most recent call last):  
File “event:propertyChange”, line 7, in   
TypeError: getComponent(): 1st arg can’t be coerced to int

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 30, 2014, 12:47pm UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/6 "2014-04-30T12:47:32Z")

</div>

Is this propertyChange script on the parent template, not on one of the templates within the template?

Because if so the referencing event.source.parent.getComponent doesn’t work.

In addition your counting custom variable should be an Integer instead of a String.

Try this script:

```auto
#Only run this script if the instanceName property changes
if event.propertyName == "instanceName":
   if event.source.instanceName == 'testTemplate1':
      event.source.thisValue = 1
   elif event.source.instanceName == 'testTemplate2':
      event.source.thisValue = event.source.getComponent('testTemplate1').thisValue + 1
   elif event.source.instanceName == 'testTemplate3':
      event.source.thisValue = event.source.getComponent('testTemplate2').thisValue + 1
```

Nick Mudge  
Ignition Consultant  
[nickmudge.info](http://nickmudge.info)

---

<div class="post-metadata">

**Author:** ![rdeavers](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rdeavers](https://forum.inductiveautomation.com/u/rdeavers)\
**Post date:** [April 30, 2014, 4:46pm UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/7 "2014-04-30T16:46:18Z")

</div>

I still receive the same error. Here is an example of my form with multiple instances of the template inside. I have a button from another form calling testWindow.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [May 4, 2014, 3:45am UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/8 "2014-05-04T03:45:33Z")

</div>

Hi rdeavers,

I imported the template and window into Ignition. There is no scripts on them. How do I reproduce the issue?

Thanks  
Nick Mudge  
Ignition Consultant  
[nickmudge.info/](http://nickmudge.info/)

---

<div class="post-metadata">

**Author:** ![rdeavers](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rdeavers](https://forum.inductiveautomation.com/u/rdeavers)\
**Post date:** [May 5, 2014, 4:10pm UTC](https://forum.inductiveautomation.com/t/accessing-templates-from-another-template/8390/9 "2014-05-05T16:10:08Z")

</div>

My issue was accessing a template on a form from another template on the same form. To do this, I was using:

```auto
event.source.parent.getComponent
```

However, I learned from tech support that templates are in another container so the correct way to do what I needed is add another parent level.:

```auto
event.source.parent.parent.getComponent
```

My program now works correctly. I do appreciate the help.
