# sendMessage causing script to stop execution

**URL:** <https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 24, 2025, 1:50pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091 "2025-03-24T13:50:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Smith](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Jeffrey\_Smith](https://forum.inductiveautomation.com/u/Jeffrey_Smith)\
**Post date:** [March 24, 2025, 1:50pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091/1 "2025-03-24T13:50:24Z")

</div>

I am having an issue where system.perspective.sendMessage seems to stop execution of a change script.

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	from time import sleep 
	
	def confirm_reset():
		sleep(5)
		if self.custom.timingActive or self.custom.interruptFlag:
			self.custom.timingActive = False
			system.perspective.sendMessage('changeMessage', payload={'text': 'script', 'instanceId': self.view.custom.instanceId}, scope='page')
			self.custom.interruptFlag = True
			
	if currentValue.value:
		system.util.invokeAsynchronous(confirm_reset, [], "Confirm Delay")

```

I have split the 2 properties interruptFlag and timingActive to help me see what was going on. As posted, interruptFlag does not get set. As soon as I comment out the system.perspective.sendMessage, interruptFlag will be set as expected. I have been over and over this code to see what I may have fat fingered and can't find anything.

Any help would be greatly appreaciated.

---

<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:** [March 24, 2025, 2:07pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091/2 "2025-03-24T14:07:12Z")

</div>

Unless your version of Ignition is really recent, `system.util.invokeAsynchronous()` does not inherit the Perspective environment needed by `system.perspective.sendMessage()`. So that call will fail.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Smith](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Jeffrey\_Smith](https://forum.inductiveautomation.com/u/Jeffrey_Smith)\
**Post date:** [March 24, 2025, 2:08pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091/3 "2025-03-24T14:08:12Z")

</div>

Running 8.1.44

---

<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:** [March 24, 2025, 2:16pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091/4 "2025-03-24T14:16:20Z")

</div>

I don't recall what version has that enhancement, and it is not showing in the v8.1 changelogs. I recall @paul-griffith making a comment that it was added.

You have `self` in your closure, so you should be able to extract explicit session and page information from that to use in `system.perspective.sendMessage()`.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Smith](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Jeffrey\_Smith](https://forum.inductiveautomation.com/u/Jeffrey_Smith)\
**Post date:** [March 24, 2025, 2:23pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091/5 "2025-03-24T14:23:50Z")

</div>

I tried sending the sessionID to it but it still didn't work. As a workaround, I've moved the sendMessage outside of the called function and leveraged the second call of the change script (false transition) to send the message.

---

<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:** [March 24, 2025, 2:26pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091/6 "2025-03-24T14:26:35Z")

</div>

When using page scope for your message, you **must** supply both session and page IDs.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 24, 2025, 3:20pm UTC](https://forum.inductiveautomation.com/t/sendmessage-causing-script-to-stop-execution/104091/7 "2025-03-24T15:20:29Z")

</div>

I thought I had made that change too, but git blame suggests not. I think I intended to, but wasn't able to with the fragile `ScriptContext` API in 8.1 (the change _has_ been made to inherit `ScriptContext` in 8.3).

However, Perspective's session info is in a dedicated `ThreadLocal` and therefore not part of `ScriptContext` anyways, so it's a moot point.
