# Perpective - Stop script on modal Popup

**URL:** <https://forum.inductiveautomation.com/t/perpective-stop-script-on-modal-popup/35748>\
**Category:** Ignition\
**Created:** [June 17, 2020, 12:56pm UTC](https://forum.inductiveautomation.com/t/perpective-stop-script-on-modal-popup/35748 "2020-06-17T12:56:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luc.martin](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@luc.martin](https://forum.inductiveautomation.com/u/luc.martin)\
**Post date:** [June 17, 2020, 12:56pm UTC](https://forum.inductiveautomation.com/t/perpective-stop-script-on-modal-popup/35748/1 "2020-06-17T12:56:04Z")

</div>

Is there a way that we can stop a script while a popup is opened?

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 17, 2020, 1:18pm UTC](https://forum.inductiveautomation.com/t/perpective-stop-script-on-modal-popup/35748/2 "2020-06-17T13:18:12Z")

</div>

If the running script is a loop, at the beginning of each loop you could check for a custom property on your view called “isPopupOpen” and it be defaulted to false

Then when the popup opens, send a message to the page scope, and toggle the bit true

Then when your popup closes, same thing but toggle it false again.

If the popup closing doesn’t allow you to do that. You could essentially setup a watchdog between the root container and the popup that when the popup is open, every 3 seconds it polls and sets that bit to true + a last comm time, and then the root container is every 5 seconds looking at the bit being true and the comm time being older than 5 seconds ago, if that’s the case then it sets it false

That’s just a rough idea of how you could do that, however I inherently am thinking that the script should maybe be working differently if this is what’s needed. But I don’t know anything about the script

If you need an example let me know, I can mock one up

---

<div class="post-metadata">

**Author:** ![luc.martin](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@luc.martin](https://forum.inductiveautomation.com/u/luc.martin)\
**Post date:** [June 17, 2020, 1:22pm UTC](https://forum.inductiveautomation.com/t/perpective-stop-script-on-modal-popup/35748/3 "2020-06-17T13:22:13Z")

</div>

How do you build you watchdog to valid is popup is opened?

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 17, 2020, 2:38pm UTC](https://forum.inductiveautomation.com/t/perpective-stop-script-on-modal-popup/35748/4 "2020-06-17T14:38:47Z")

</div>

1. On the main view I created two properties, one to to interrupt the script, and one to show popup communication  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4668b13c97eacb730ab81e5853cfab24892f1fc7.png)
2. The binding on the isPopupOpen property is an expression, that checks to see if the last update was greater than 2 seconds ago

```auto
if(secondsBetween({view.custom.lastWatchdogUpdate}, now(1000)) > 2, False, True)

```

1. Then I created a fake script that increments a gauge, but checks that the popup isnt open first, this is polling every second

```auto
currValue = self.props.value
	if not self.view.custom.isPopupOpen:
		if currValue >= 120:
			currValue = 0
		else:
			currValue += 1
	return currValue

```

1. Then I added a message handler to my component, in the page scope, that sets the “lastWatchdogUpdate” property to now  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6ae9f02fe8585d5286b04b19a542cfd219d57e69.png)
2. Then on my popup I created a custom property, polling at 1 second, that calls my message

```auto
system.perspective.sendMessage(messageType="watchdogUpdate", scope="page")
	return value

```

1. Then I add a button to my test view to open the popup

et. voila  
 ![timer](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8c63b51cbc33772337074225fde94b0bd0b5443d.gif)

Here is a copy of the project as well, let me know if you have any questions!  
[Popup\_Interrupt\_20200617143745.zip](https://forum.inductiveautomation.com/uploads/short-url/7obb5UN9D859OVinwaPzCWDPDSv.zip) (9.3 KB)

---

<div class="post-metadata">

**Author:** ![luc.martin](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@luc.martin](https://forum.inductiveautomation.com/u/luc.martin)\
**Post date:** [June 17, 2020, 2:56pm UTC](https://forum.inductiveautomation.com/t/perpective-stop-script-on-modal-popup/35748/5 "2020-06-17T14:56:13Z")

</div>

Will try, thanks.
