Accessing a Perspective Component on a View from within a popup

Hi all,

I am currently working on a project which requires a popup to be able to run a method on a component on another view (more specifically the map components flyTo() method).

I was wondering if there is anyway of accessing another views root container from Perspective (as you can in Vision through hierachies and the system.nav / system.gui package).

I did try something along the lines of:

component = self.page.props.primaryView.getChild("root").getChild("Map")
component.flyTo(args)

but this unfortunately seems to not yield the results I am looking for instead if I catch the error and print it to console I am provided with the message:

'unicode' object has no attribute 'getChild'

which I assume just means that self.page.props.primaryView is not an object representing the view (as I hoped it was).

Thanks for reading! Any ideas are appreciated,

MG3.

You need to make use of system.perspective.sendMessage() to send a message in the page context.

On your map you'll need to create a message handler to listen at the correct scope and handle the payload provided by the message sent by the popup.

Edit - @bschroeder fastest hands in the west :stuck_out_tongue_closed_eyes:

3 Likes

You would use the system.perspective.sendMessage | Ignition User Manual function to pass that data.

Create a session level message on the map, and call that message handler with the payload that you want to pass. The session level message on the map would digest the payload and do the flyTo function based on that payload.

Edit - Nerd snipped by @ryan.white

2 Likes

Expanding on this, in perspective each view runs isolated from the others, so you cannot access one view from another like you could in vision.

Session custom props and messages/message handlers are the only way to transfer data between views.

Also keep in mind the view has to be open for any handlers on it to consume their respective messages.

1 Like

Thanks @ryan.white and @bschroeder will have a look into this. Don't often touch perspective so this is and the method and explanation is appreciated (as I will be diving into it and getting more involved in it). Also hope this helps someone in the future as I had real trouble looking for the solution to this!

Bonus Note for anyone reading this. Ensure you set your scope when using system.perspective.sendMessage() to deliver session messages. Scratched my head for a while not realising the scope defaults to page if not specified.

system.perspective.sendMessage("handler", payload, scope="session")

There is a meaningful difference between the scopes. For example if the user has two tabs open under the same session, both pages will call the fly to method if you use the session scope. Page scope will only affect the page they're interacting with. Possibly an extremely edge case or inconceivable, but being such a simple thing to design for, we may as well

1 Like