Property Change Script On Window Open

I have a script that runs when a property changes on a label. The script will popup an error window, the only time it causes issue is when the window with the label is opened, I don’t want the script to run when the window is first loaded. Any way to bypass this ?

What changes the label?

( Vision or Perspective? )

Basically I have a field that you enter in a number, there is a seperate tag that reads that number and queries a database and returns a date, the label with the script is reading that date.

You didn’t say if this is vision or perspective.

If this is vision and this is an event script, make sure you are filtering the script to only execute when the property you are interested in changes.

If can share your script, or the error you are getting, we will be able to help you better.

This is vision, how can I filter the script like that?

The event gives you access to the propertyName that triggered the change. If a script is unfiltered then it will run when you are not intending it to.

Filter it by checking the propertyName that triggered the event against the name of the property you are interested in.

if event.propertyName == 'intValue':
    #do your work here

Tried this, filtering by the event.propertyName == ‘text’ because the text is what I want to execute the script on change for. The script still fires on open for the window. The text of the label is linked to a tag but that tag value is not changing when I open the window

Can you share a screen shot of where you are editing this script?

It should be on the component that is changing not the one that you want to change, and not on the window.

But it is changing from the label's deserialized initial value--the last value present when the window was last edited and saved in the designer.

Is there a way to avoid this? Does the property change event have a parameter like initialChange or something?

A window load will cause a text property change on a label but the event.oldValue is type<java.lang.Object> which might be a way to distinguish window loads from actual text changes. I don’t know if this is bad practice or not, but it did work on a quick test.

if event.propertyName == 'text':
	if isinstance(event.oldValue, unicode):
		// do something

Unfortunately that didn’t work. I am doing this property change event on a text field. That text field has a tag binding and found in a template that’s repeated 3 times on a screen.

It must be something with the template, a single text field by itself didn’t fire on designer save

@pturmel do you think there’s any way around this? Still having the issue.

Try using a propertyChange event where propertyName=‘componentRunning’ in a state machine. Ignore the relevant propertyChange events that fire before componentRunning becomes true. (It isn’t a true property, though, so you’ll need to save it somewhere.)

I had a similar problem, only using event.newValue. I notice that this value evaluates to None during the initial change. My particular circumstance allowed me to add a condition to only run the script if (event.value != None). This is pretty specific to my scenario, but something like that might be useful in other cases.