# Message Handler Help

**URL:** <https://forum.inductiveautomation.com/t/message-handler-help/64355>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [September 22, 2022, 1:32am UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355 "2022-09-22T01:32:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 22, 2022, 1:32am UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/1 "2022-09-22T01:32:07Z")

</div>

Hello,

I am experimenting with the message handler, using the docs here:  
[https://docs.inductiveautomation.com/display/DOC80/Component+Message+Handlers](https://docs.inductiveautomation.com/display/DOC80/Component+Message+Handlers)

But this simple script does not work in preview mode or in the browser.

Thoughts?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 22, 2022, 1:47am UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/2 "2022-09-22T01:47:59Z")

</div>

So, the Hello text does not work, but the lower portion of the docs passing the time payload works…

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 22, 2022, 8:55pm UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/3 "2022-09-22T20:55:42Z")

</div>

Please post your code.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 22, 2022, 9:48pm UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/4 "2022-09-22T21:48:47Z")

</div>

> [@mdemaris](#):
>
> But this simple script does not work

No one can help you without the code.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 22, 2022, 11:34pm UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/5 "2022-09-22T23:34:31Z")

</div>

Hm, yes that’s true. I deleted the first attempt and tried it again… now it works.  
Label:

```auto
def onMessageReceived(self, payload):
	"""
	This method will be called when a message with the matching type code
	arrives at this component.

	Arguments:
		self: A reference to this component
		payload: The data object sent along with the message
	"""
	# implement your handler here
	self.props.text = 'Hello'

```

Button

```auto
def runAction(self, event):
	"""
	This event is fired when the 'action' of the component occurs.

	Arguments:
		self: A reference to the component that is invoking this function.
		event: An empty event object.
	"""
	messageType = 'mh1'
	system.perspective.sendMessage(messageType)

```

IDK - the first time, nothing. Well, it works now, so I am moving forward!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 23, 2022, 2:38pm UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/6 "2022-09-23T14:38:30Z")

</div>

Beware that the default scope for sendMessage is “page”. Perhaps you were using a different page the first time around?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [September 23, 2022, 4:05pm UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/7 "2022-09-23T16:05:52Z")

</div>

Well, assuming I followed the directions, lol, the view box should have been the only one checked. But I can’t go back in time!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 23, 2022, 4:42pm UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/8 "2022-09-23T16:42:04Z")

</div>

The docs are wrong; that example provides no scope to the function call and so it will default to “page”, but the checkbox specified in the images is “view”. This will result in the example not working until you either use the page scope checkbox or you modify the function to use a scope of “view”.

I’ve reached out to the Docs team to update the example.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 3, 2022, 7:10pm UTC](https://forum.inductiveautomation.com/t/message-handler-help/64355/9 "2022-10-03T19:10:45Z")

</div>

The Documentation team has updated the script example to specify a scope of "view".
