Message Handler in Perspective

Hi All,

I created a header that would allow me to open a popup where I can select a unit, and then I would use the message handler to pass the unit name back to my header.

The problem I am having is that the value of the custom property that I created under the root called “Unit” is not updating every time I tried to execute system.perspective.sendmessage. The custion property would only remain in its initial input but not updating to what is being passed in.

system.perspective.sendMessage('UnitName', payload={'Unit':str(self.view.custom.Unit)}, scope='session')

on the receiving end:

self.custom.Unit = str(payload['Unit'])

What scope is the handler listening on? Based on the “broadcast”, your listener needs to be listening on the “session” scope.

Also, are you confident the “broadcast” is occurring? I’ve seen some usages where the invocation of sendMessage occurs after the Popup has been closed, which results in the script not completing. Make sure the sendMessage invocation is being completed by placing logging immediately after it and verifying that you see that logging when you expect to.

The issue occurred because of the persistent property on the custom property. I had to use a different approach to achieve what I wanted to do. But to your question, the broadcast did occur every time it got executed.

Persistence should not prevent you from writing to the property. If a property is Persistent, it just means that the property will exist as-is when a session/view/component start up. If it were not Persistent, the property would not exist until you wrote to it.

Could you elaborate on how the Persistence of the property was the issue?

The persistent property is keeping the custom value that I created to its default/initial value (for instance: T100) if I decided to go to other screens and then went back to my screen. What I wanted the custom property to be is whatever I last selected (it can be T200 right now) in the popup, but persistent property is limiting the ability to do so because perspective will default it back to T100.

Ah, yes - every time you load the View it will load the Persistent value back into place. If you need that value to be something different during the course of a Session, then you’d be better off storing it as a session property or in a database.

1 Like