# Template load event?

**URL:** <https://forum.inductiveautomation.com/t/template-load-event/16237>\
**Category:** Ignition\
**Tags:** ignition79, scripting, vision\
**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:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [February 27, 2024, 10:58pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/21 "2024-02-27T22:58:21Z")

</div>

> [@dkhayes117](#):
>
> I think you are looking for this, add this to your propertyChange event
> 
> ```python
> if event.propertyName == 'componentRunning':
> execute your code
> 
> ```
> 
> the code will only execute when the componentRunning property is true

~~This approach doesn't seem to work for templates within a template repeater. v8.1.35~~

Actually, it does work, but _it works too fast._ The script that I need to run checks a few bindings within the template to see if they're null or not, but it runs so fast that they're all null. - since that's the case I've used property change on the values that I'm waiting for since they'll transition from null to not null.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [February 28, 2024, 2:40pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/22 "2024-02-28T14:40:18Z")

</div>

That is still not quite working for me. It seems that only sometimes it will transition from null to not null.

Here's what I've got.

1. 4 custom (double) props, indirectly bound to tag values.
2. Custom dataset prop. 1 string column with names of available props.

I need the dataset to start empty (save template with an empty dataset) and have a script run to fill the dataset based on those 4 custom double props. The script is simple and works as expected, I just can't get it to fire reliably when the template opens, after the 4 props are "loaded."

I've also tried writing the 4 props to 0 on component startup to "force" a change once the binding is made, but that doesn't seem to work either.

```auto
prop = event.propertyName

if prop == 'componentRunning':
	event.source.total = 0
	event.source.today = 0
	event.source.week = 0
	event.source.year = 0

if prop == 'total' or prop == 'today' or prop == 'week' or prop == 'year':

	headers = ['label']
	data = []
		
	if event.source.total is not None:
		data.append(['Total'])
	if event.source.today is not None:
		data.append(['Today'])
	if event.source.week is not None:
		data.append(['Week'])
	if event.source.year is not None:
		data.append(['Year'])
		
	event.source.avail = system.dataset.toDataSet(headers, data)

```

\*\*edit adding the componentRunning to set props to 0 seems to work

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [March 2, 2024, 9:58pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/23 "2024-03-02T21:58:32Z")

</div>

> [@amarks](#):
>
> it works too fast

You could also put all of that into a function and use invokeLater to properly schedule it.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 4, 2024, 2:57pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/24 "2024-03-04T14:57:28Z")

</div>

The question then becomes, how much later? Are you wasting time waiting? What do you do with the binding while waiting?

Forcing the values to 0 first results in a valid binding when the value is 0 and as soon as the binding is ready it overwrites that 0.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [March 4, 2024, 4:11pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/25 "2024-03-04T16:11:33Z")

</div>

Normally in this situation, I don't put a delay at all. Invoke later automatically schedules the function after everything else that is already scheduled to run in the EDT, so you know what you are calling will run last.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 4, 2024, 8:53pm UTC](https://forum.inductiveautomation.com/t/template-load-event/16237/26 "2024-03-04T20:53:39Z")

</div>

Didn't realize that invokeLater would do that for you, without a delay. Good to know.

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