# Ignition template property change script

**URL:** <https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146>\
**Category:** Ignition\
**Created:** [June 24, 2022, 1:23am UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146 "2022-06-24T01:23:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkchan](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@gkchan](https://forum.inductiveautomation.com/u/gkchan)\
**Post date:** [June 24, 2022, 1:23am UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/1 "2022-06-24T01:23:50Z")

</div>

I have implemented a property change script for a template window to resize itself when its property value changes. This property value is tied to a tag value.  
However, i notice sometimes this property change script is not invoked even though the binded tag value changes.

What could cause this property change script not to be invoked? Is there a way to workaround it?

---

<div class="post-metadata">

**Author:** ![obober](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/obober/32/67865_2.png) [@obober](https://forum.inductiveautomation.com/u/obober)\
**Post date:** [June 24, 2022, 6:33pm UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/2 "2022-06-24T18:33:45Z")

</div>

Do you have any conditional statements in your property change script? It’s common for property change scripts to have conditionals like `if currentValue == True` or something along the lines of that. Maybe you’re preventing the property change script from executing?

---

<div class="post-metadata">

**Author:** ![gkchan](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@gkchan](https://forum.inductiveautomation.com/u/gkchan)\
**Post date:** [June 28, 2022, 1:49pm UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/3 "2022-06-28T13:49:52Z")

</div>

Have, i am checking the custom property’s propertyName and value in the if condition. I have checked the conditions are met, but somehow the script is not being executed.

Any idea why?

---

<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:** [June 28, 2022, 1:52pm UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/4 "2022-06-28T13:52:34Z")

</div>

We aren’t telepathic. (Well, _ **I’m** _ not.) Show your code. Provide details of your template and the tag binding.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 28, 2022, 1:53pm UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/5 "2022-06-28T13:53:36Z")

</div>

> [@pturmel](#):
>
> We aren’t telepathic. (Well, _ **I’m** _ not.)

You haven't made a module for this yet ?

---

<div class="post-metadata">

**Author:** ![gkchan](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@gkchan](https://forum.inductiveautomation.com/u/gkchan)\
**Post date:** [June 29, 2022, 1:49am UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/6 "2022-06-29T01:49:58Z")

</div>

Hi,

Here’s my code. Appreciate some advice and suggestions here.

```auto
if event.propertyName == 'intTogglePopup':
	if event.source.intTogglePopup == 0:
		component = event.source	
		rootContainer = event.source.parent
		currentZOrder = rootContainer.getComponentZOrder(component)
		try:
			#Change the minus to a plus to move the Z Order/Index of the Object/Component to a higher 'layer'
			rootContainer.setComponentZOrder(component,0)
			component.requestFocusInWindow()
		except:
			pass	
	
		objComp = event.source
		origX = objComp.x
		origY = objComp.y
		intNewWidth = 0
		intNewHeight = 0
			
		system.gui.transform(
			objComp,
			origX,origY, intNewWidth, intNewHeight,
			duration=500,
			acceleration=system.gui.ACCL_FAST_TO_SLOW
		)		
	else:
		component = event.source	
		rootContainer = event.source.parent
		currentZOrder = rootContainer.getComponentZOrder(component)
		try:
			#Change the minus to a plus to move the Z Order/Index of the Object/Component to a higher 'layer'
			rootContainer.setComponentZOrder(component,0)
			component.requestFocusInWindow()
		except:
			pass
		objComp = event.source
		origX = objComp.x
		origY = objComp.y
		intNewWidth = 1920
		intNewHeight = 1080
			
		system.gui.transform(
			objComp,
			origX,origY, intNewWidth, intNewHeight,
			duration=500,
			acceleration=system.gui.ACCL_FAST_TO_SLOW
		)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 29, 2022, 8:02am UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/7 "2022-06-29T08:02:48Z")

</div>

I’m not sure I can help with debugging, but here’s a suggestion: Don’t duplicate things. Here, most of the code is common to both branches of the if/else. Reassemble everything and only leave in the if/else what NEEDS to be there:

```python
if event.propertyName == 'intTogglePopup':
	component = event.source	
	rootContainer = event.source.parent
	currentZOrder = rootContainer.getComponentZOrder(component)
	try:
		#Change the minus to a plus to move the Z Order/Index of the Object/Component to a higher 'layer'
		rootContainer.setComponentZOrder(component, 0)
		component.requestFocusInWindow()
	except:
		pass

	objComp = event.source
	origX = objComp.x
	origY = objComp.y

	if event.source.intTogglePopup == 0:
		intNewWidth = 0
		intNewHeight = 0			
	else:
		intNewWidth = 1920
		intNewHeight = 1080
			
	system.gui.transform(
		objComp,
		origX, origY, intNewWidth, intNewHeight,
		duration=500,
		acceleration=system.gui.ACCL_FAST_TO_SLOW
	)

```

Makes things easier to read and follow.

if `event.source.intTogglePopup` can only be 0 and 1, I’d suggest one of two things:

1. Make it a boolean
2. Use that to compute your values instead of using if/else:

```python
intNewWidth = 1920 * event.source.intTogglePopup
intNewHeight = 1080 * event.source.intTogglePopup

```

Then, I’m a bit confused about a few things:

- you’re not using `currentZOrder`. Did you forget to use it somewhere ?
- I fail to see how the code in the try/except does what the comment says. How does `setComponentZOrder(component, 0)` changes a minus to a plus ?

---

<div class="post-metadata">

**Author:** ![gkchan](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@gkchan](https://forum.inductiveautomation.com/u/gkchan)\
**Post date:** [June 29, 2022, 10:22am UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/8 "2022-06-29T10:22:52Z")

</div>

hi

event.source.intTogglePopup will be 0 when we want to close the popup. event.source.intTogglePopup can be more than 1 to differentiate the different popups that we have. hence we can’t make event.source.intTogglePopup as boolean.

the issue where the above script didn’t get triggered is happening intermittently not always.

Any idea why above script didn’t get triggered is happening intermittently?

---

<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:** [June 29, 2022, 11:12am UTC](https://forum.inductiveautomation.com/t/ignition-template-property-change-script/61146/9 "2022-06-29T11:12:05Z")

</div>

Consider adding a single line `print event` (temporarily) above the first line. Open the debug console while you recreate the problem. Examine the console to confirm that an event for `intTogglePopup` is happening when expected, and if so, that it contains the expected values.

(Don’t leave the `print` statement in place–it will be very noisy.)
