Load PDF Viewer in popup

I’m storing data/BLOB in MySQL to view PDFs. I can easily get things to work if the PDF Viewer is in the window where I’m ‘calling’ the database.

event.source.parent.getComponent('PDF Viewer').loadPDFBytes(bytes,name)

But, what if I want this viewer in a popup? How do I pass the values? I tried creating custom properties of string type but that didn’t work. Can someone push me in the right direction?

FYI, I was using internalFrameActivated…

name = system.gui.getParentWindow(event).getComponentForPath('Root Container').FileName
bytes = system.gui.getParentWindow(event).getComponentForPath('Root Container').Bytes
system.gui.getParentWindow(event).getComponentForPath('Root Container.PDF Viewer').loadPDFBytes(bytes, name)

You can set custom properties on the root container of your pop up - these will be parameters you can pass in.

Then you can do something like

system.nav.openWindow("Pop_OpenWindow", {"param1":value, "param2":value,..})

https://docs.inductiveautomation.com/display/DOC79/system.nav.openWindow

I’m not asking how to pass parameters, that’s simple, what I’m asking is passing bytes to the PDF Viewer. Using string data type didn’t work.

Edit: FileName & Bytes are my custom properties…

My fault. So you’re passing the entire bytes as a paramter and then do system.gui.getParentWindow(event).getComponentForPath('Root Container').Bytes? I think you’re better off just passing in the id of the row in the db that you want, and then in the internalFrameActivated, querying for the blob data and doing everything there. I wouldn’t try to pass bytes or blob data via paramter.

There’s no (reliable) way to store raw bytes directly in a Vision custom property. The only supportable way would be to define a Dataset property, and pass the bytes in a 1Rx1C dataset.

Thanks, not sure why I didn’t think of that. Appreciate the push!!

Nit to pick: Y’all are doing this in a window event:

b = system.gui.getParentWindow(event).getComponentForPath('Root Container').Bytes

But a window event’s source is the window, and a window has a rootContainer property. This is far more readable (and faster):

b = event.source.rootContainer.Bytes

The property and tag lookup helpers in the script editor have no concept of optimizations or temporary variables or use of event properties. You shouldn’t treat their generated code as gospel.

4 Likes

I personally never knew we could still use event.source in window events, I thought the system.giu.getParentWindow stuff was necessary since the property lookup always used it. Good to know! Why the difference in syntax if we can still just use event.source?

Nit pick away, I’m always up for learning something better. I’ll admit, I’m lazy and just the let the software do the path for me.

1 Like

The property/tag pickers are not context sensitive. They don’t “know” what kind of event they are working in.

You should also consider, when dealing with multiple properties of a selected component, to store the component in a temporary variable in the script. Then multiple operations can be done with its properties without “getting” it every time.

3 Likes