Template load event?

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.

1 Like

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.

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

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

1 Like

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.

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.

2 Likes

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