Perspective messages function correctly in Designer but are non-functional when launched in browser

I'm creating an inspection form for a series of truss members within a wooden rollercoaster frame. However I'm having an issue passing information (the name of the member) from the truss elevation view (view 1) to the inspection form (view 2). The messages and message handlers seem to work in the designer view, but not in the browser

View 1(Truss):

View 2(Inspection from):

I've scripted the 'onClick' for each truss member in view 1 to send the message:
def runAction(self, event):

	messageType = 'Selected_MemberTag'
	payload = {'MemberTag':self.meta.name}
	system.perspective.sendMessage(messageType, payload, scope='session', sessionId = self.session.props.id, pageid = 'Inspection_Form');

It then Navigates to the inspection form (view 2) where a label's text field is changed to display the member that was selected in the previous screen:
def onMessageReceived(self, payload):

self.props.text = "Selected Member: " + payload['MemberTag'];

The messages work in the designer view, but not when I launch the project in browser. I suspect that the messages are not heard by the handlers in the browser because the message handler page isn't open when the message is sent.

Any help with this issue would be appreciated!

Cheers,
Hayden

It seems like it might be easier to achieve what you're trying to do by using parameters instead of messages.

Setting up parameters: You can add them as props under the "params" section of the view properties.
https://docs.inductiveautomation.com/display/DOC81/Views+in+Perspective#ViewsinPerspective-Input/OutputParameters

Passing parameters: Can be done by appending them to a view's page URL.
https://docs.inductiveautomation.com/display/DOC81/Pages+in+Perspective#PagesinPerspective-PassingParameters(URLParameters)

So on your view 2, you'd define a selectedMember param, and in the page configuration, configure the view 2 URL as /view2/:selectedMember. Then, to navigate, you'd do something like:

system.perspective.navigate("/view2/:{}".format(self.meta.name))

EDIT: Forgot that you can just pass parameters directly to a view and skip the entire URL setup portion:

system.perspective.navigate(page="/view2", params={"selectedMember":self.meta.name})

You're encountering an idiosyncrasy of the Designer because it doesn't actually have true "pages". In the Designer, the pageId you see is actually the name of the View tab you're examining in the Designer. At runtime in a session, however, that value is dynamically generated and unique per browser tab. If you don't have to send messages to other sessions or target other tabs of the current session, there is no need to supply the sessionId or pageId arguments of the sendMessage function.

4 Likes

Thank you! This solution worked for my instance

Thanks, I did try this solution but didn't manage to get it to work. Ie; I removed the 'sessionid' and 'pageid' arguments from the system.perspective.sendmessage function.
I managed to get it functioning by passing parameters from Felipe_CRM's solution. What would be the 'best practice' solution? Sending messages or passing parameters?

one can be used as popup the other not rly, so its up to you which you need.

2 Likes

Passing parameters is always preferred; it's much simpler and more obvious

2 Likes