# Property Change Script On Window Open

**URL:** <https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [February 15, 2021, 4:08pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422 "2021-02-15T16:08:29Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [February 15, 2021, 4:08pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/1 "2021-02-15T16:08:29Z")

</div>

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 ?

---

<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:** [February 15, 2021, 4:17pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/2 "2021-02-15T16:17:27Z")

</div>

What changes the label?

( Vision or Perspective? )

---

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [February 15, 2021, 4:33pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/3 "2021-02-15T16:33:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 15, 2021, 4:38pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/4 "2021-02-15T16:38:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [February 15, 2021, 4:40pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/5 "2021-02-15T16:40:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 15, 2021, 4:55pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/6 "2021-02-15T16:55:28Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [February 15, 2021, 5:37pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/7 "2021-02-15T17:37:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 15, 2021, 5:45pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/8 "2021-02-15T17:45:59Z")

</div>

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.

---

<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:** [February 15, 2021, 8:00pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/9 "2021-02-15T20:00:42Z")

</div>

> [@rrebro](#):
>
> The text of the label is linked to a tag but that tag value is not changing when I open 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.

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [February 11, 2022, 2:34pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/10 "2022-02-11T14:34:12Z")

</div>

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

---

<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 11, 2022, 3:09pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/11 "2022-02-11T15:09:48Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [February 11, 2022, 3:15pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/12 "2022-02-11T15:15:39Z")

</div>

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.

---

<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 11, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/13 "2022-02-11T15:29:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [February 17, 2022, 7:55pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/14 "2022-02-17T19:55:41Z")

</div>

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

---

<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:** [February 17, 2022, 8:00pm UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/15 "2022-02-17T20:00:42Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![CharlieW](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@CharlieW](https://forum.inductiveautomation.com/u/CharlieW)\
**Post date:** [April 6, 2022, 1:15am UTC](https://forum.inductiveautomation.com/t/property-change-script-on-window-open/43422/16 "2022-04-06T01:15:11Z")

</div>

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.
