# Template load event?

**URL:** <https://forum.inductiveautomation.com/t/template-load-event/16237>\
**Category:** Ignition\
**Tags:** ignition79, vision, scripting\
**Created:** [December 6, 2017, 9:20pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237 "2017-12-06T21:20:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [December 6, 2017, 9:20pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/1 "2017-12-06T21:20:14Z")

</div>

Is there an event that fires when a template is first loaded, similar to the visionWindowOpened() on vision windows?

For context: I'm trying to set default values for the components inside a template that can still be changed by the user. I imagine there might be a better way? 🙂

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [December 6, 2017, 11:10pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/2 "2017-12-06T23:10:23Z")

</div>

I’m trying to avoid pasting the template components directly in the window container.

Is it possible to access template components through the window somehow? There’s no compatible getComponent() for template holders…

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [December 6, 2017, 11:17pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/3 "2017-12-06T23:17:44Z")

</div>

I don’t think there’s anything official, but you can probably take advantage of the propertyChange event function. Looks like property “componentRunning” could be good - I think that only goes true when it starts up. It also goes to false when the template is unloaded, which could be useful.

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [December 7, 2017, 5:52pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/4 "2017-12-07T17:52:47Z")

</div>

Thanks, great solution!

---

<div class="post-metadata">

**Author:** ![andytimc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/andytimc/32/11938_2.png) [@andytimc](https://forum.inductiveautomation.com/u/andytimc)\
**Post date:** [February 20, 2019, 7:19pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/5 "2019-02-20T19:19:27Z")

</div>

mrogers, I think this could solve my problems and I was hoping to get a little more info. When my template repeater loads my propertychange event runs numerous time even though the user has not changed the value. From what you are saying can I check that the componentRunning has gone true before I let the propertychange script run?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 20, 2019, 7:48pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/6 "2019-02-20T19:48:07Z")

</div>

I think you are looking for this, add this to your propertyChange event

```auto
if event.propertyName == 'componentRunning':
       execute your code

```

the code will only execute when the componentRunning property is true

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 19, 2020, 12:03pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/7 "2020-08-19T12:03:49Z")

</div>

I have a template in which I am calling runScript function on the expression of one of the properties by passing other properties as parameters. It gets called multiple times when the window containing the template repeater which loads this template is opened. I am assuming it happens due to other parameters properties changing on window open event.  
I think using invokeLater function would resolve this issue, which I am running on `componentRunning`  
propertyChange event but nothing seems to be happening.  
I have added same code as above in template’s propertyChange event. Am I missing something?

Edit: I am using Ignition 8.0.12

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 20, 2020, 10:54am UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/8 "2020-08-20T10:54:57Z")

</div>

Can anyone help on this? I need it urgently.

Thanks.

---

<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:** [August 20, 2020, 11:39am UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/9 "2020-08-20T11:39:01Z")

</div>

Show your code, and we might be able to help.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 21, 2020, 11:07am UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/10 "2020-08-21T11:07:59Z")

</div>

@pturmel Thank you for your reply.

Below is my code that I have written on the `propertyChange` event of the template which I am calling in the template repeater on a window.

```auto
if event.propertyName == 'componentRunning':
    print 'Property Changed'
	system.util.invokeLater(func, 500)

```

Issue is this script is not getting fired, it’s not printing anything.

---

<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:** [August 21, 2020, 11:47am UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/11 "2020-08-21T11:47:20Z")

</div>

The “root” of a template is a bit odd. Try placing that on a dummy component inside the template.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 21, 2020, 12:59pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/12 "2020-08-21T12:59:17Z")

</div>

Thank you @pturmel for your prompt help.

Actually I put same script on the label component as suggested by you. But while saving I accidentally selected Gateway option on conflict window and basically reverted to old code. But now whenever I open template or window in designer by putting it in preview mode first, I can see the printed message in output console. I am sure I had checked previously also in the same way. But somehow it’s working now.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 21, 2020, 2:33pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/13 "2020-08-21T14:33:52Z")

</div>

I am facing another issue now. I have code like below in template’s `propertyChange` event

```auto
if event.propertyName == 'componentRunning':
     print 'Running'
     def getValues():
          property1 = event.source.property1
          property2 = event.source.property2
          datasetValues = func(property1, property2)
     system.util.invokeLater(getValues, 500)

```

property1, property2 etc. are internal properties on templates which are bound to OPC, memory tags or is an expression. `func` is function defined in the package which takes these values and returns a dataset. But I am not getting expected values in returned dataset.

To elaborate more, property2 is an expression tag which looks up for specific value in another dataset property3. So my expression in property2 is  
`try(lookup({property3}, {property4}, 0, 'lookupColumn', 'resultColumn'), -1)`  
when I print property2 in `getValues` function, I get -1. But on template I see the correct value. Since `func` is being called with wrong values my returned dataset is also wrong.

My understanding is `invokeLater` allows us to call function after all bindings are evaluated. So it should get the correct values to pass in `func`

What changes do I need to make in above code?

---

<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:** [August 21, 2020, 4:08pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/14 "2020-08-21T16:08:54Z")

</div>

> [@Neo](#):
>
> My understanding is `invokeLater` allows us to call function after all bindings are evaluated.

This is not correct. invokeLater just waits the given number of milliseconds. This can be delayed further if many event scripts are running. It does not wait for asynchronous bindings like tags and queries.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 21, 2020, 4:37pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/15 "2020-08-21T16:37:34Z")

</div>

Thanks @pturmel for clearing it. So adding more delay can one of the potential solutions. But this would be uncertain though. May be I will need to read all required values from tags, wherever applicable, on the same componentRunning property change.

---

<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:** [August 21, 2020, 5:58pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/16 "2020-08-21T17:58:43Z")

</div>

No, because that would freeze your UI. Instead, monitor the arrival of the data you need with propertyChange events–when all is present, do the rest of the logic.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 25, 2020, 4:28am UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/17 "2020-08-25T04:28:53Z")

</div>

@pturmel Thank you for your suggestions. I am reading tag values on propertyChange events. It’s much smoother now.

---

<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:** [August 25, 2020, 12:10pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/18 "2020-08-25T12:10:01Z")

</div>

> [@Neo](#):
>
> I am reading tag values on propertyChange events.

Do you mean you are monitoring for propertyChange on a property with a tag binding? Or do you mean you are using `system.tag.read....()` to get the values? If the latter, don't.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [August 26, 2020, 4:09am UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/19 "2020-08-26T04:09:03Z")

</div>

I am checking for propertyChange on a property which has a tag binding.

---

<div class="post-metadata">

**Author:** ![carolina\_elfeky](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@carolina\_elfeky](https://forum.inductiveautomation.com/u/carolina_elfeky)\
**Post date:** [April 19, 2021, 8:12pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/20 "2021-04-19T20:12:14Z")

</div>

can you expand on this? I have a similar issue.

I have a template repeater and when all the data loads I want a specific values from each template to make a dataset that gets sent to a chart. I can do this manually through a button if I wait for the data to finish updating in the templates, but I want to make this automatic once all the data is done updating.

so when all templates updated get the values from loaded templates and make a dataset.

the number of templates can also change based on the parameters.

[Next page](https://forum.inductiveautomation.com/t/template-load-event/16237.md?page=2)
