Message Handler Help

Hello,

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

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

Thoughts?

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

Please post your code.

No one can help you without the code.

1 Like

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

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

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!

1 Like

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

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!

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.

4 Likes

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

3 Likes