Multiple Actions on Configure Events

I have a popup with a button. When I click (in Browser) or touch (in mobile app) I want the button to set a custom property tag value to 1, then close my popup. I am not getting the desired results.
1st attempt- I used the onClick event and configured a script to set the tag as Action #1, then used Popup action #2 to close the popup. Result- Script does not run, popup closes.
2nd attempt- I used onMouseDown event and configured a script to set the tag. I used onMouseUp event and the Popup action to close the popup. Result- Script fires and popup closes in browser with mouse. Script does not fire and popup closes in mobile app.
3rd attempt- I used onMouseDown event configured a script to set the tag. I disabled the onMouseUp event to close the popup. Result- Script fires successfully in both the browser and mobile app. (it appears here that the onMouseDown script does work for the mobile app…)
4th attempt- I used onMouseDown event configured a script to set the tag. I used onMouseUp event and the Popup action to close the popup. I added onTouchStart event and configured a script to set the tag. I used onTouchEnd event and the Popup action to close the popup. Result- Script fires and popup closes in browser with mouse. Script does not fire and popup closes in mobile app.
5th attempt- I used onTouchStart event and configured a script to set the tag. I used onTouchEnd event and the Popup action to close the popup. Result- Script does not work and popup does not close in browser with mouse. Script does not fire and popup closes in mobile app.

Suggestions? I can’t get the same behavior in both the browser and mobile app. Vision allowed scripting to both set tags and open/close windows within the same script. Can you script closing a popup in Perspective or do you have to use the popup action?
Thanks-

Hi-
It has been 2 weeks. I have a customer that needs an answer or a workaround. Can someone please look at this and reply?
Thank you

Are you passing in a unique id when opening the popup? Use that id to close it through script.

system.perspective.openPopup( "myPopupId" , 'folder/myView' , params = { 'myParam' : 1 , 'myParam2' : 'Test' }, showCloseIcon = False , resizable = True )

Then to close it:

system.perspective.closePopup( 'myPopupId' )

1 Like

Thanks for the assistance. I was using the action called popup to open the popup and I was passing in a unique (indirect) popup id. I had to change this to some other unique id since the popup that was being called to open didn’t have access to the unique id. I would have had to go back through and pass that variable up to the popup for the only purpose of being able to close it. I’m saving myself some work…anyways it is functioning the way I want now.

To follow up on some of my original issues- When I stack different actions within an event in a certain order, why did it appear they were not functioning in that order? (see my first attempt description above) By being able to order the actions, it implies they will be executed in that order, but maybe not? Even separating the action into different events of mouse down/mouse up doesn’t seem to have the desired results. Also some inconsistencies between what works for an event (ie onMouseDown) in the browser vs. mobile app. (See 2nd attempt). I would expect onMouseDown not to work at all in the mobile app and force you to use onTouchStart. If you could provide some further explanation on how the events work that would be helpful. Thanks again.

The events and how they’re handled are (unfortunately) up to the individual device and React, not anything we’re handling in our code.

Actions are fired in order, but there’s one (huge) caveat: any action that has to run on the gateway (ie, scripting, since the actual browser can’t run Python code) is basically invoked “asynchronously”. There’s no way for the frontend in your browser to “block” while waiting for a Python script to run - even if we did implement some JS interrupt, what happens if the script you’re trying to run on the gateway errors out? Or takes minutes to finish?

So, any “gateway-scoped” action can’t be relied upon to interact with a front-end object if you’re doing a “terminal” action like closing a popup. It’s unfortunate, and at minimum I’d like for us to make the UI about what’s “gateway scoped” vs “session scoped” a lot clearer in the action configuration, but it is “expected behavior”.

2 Likes

Thanks- that makes sense. Yes, maybe a clearer session vs. gateway scoped UI would be helpful. At least it would provide some insight to the user as to why things may not work as far as timing, and have the user (such as myself) take the events and actions literally as the order displayed on the screen.

1 Like

Here’s something interesting happening-
It appears that no matter what I put in the system.perspective.closePopup script as the popup id, it closes the popup anyways.
I have an event and action to open a popup, using the popup action with a unique ID of “John F Kennedy”. On the popup that opens, I have a button with a script that writes to a tag value and another line in the same script to close the popup, system.perspective.closePopup( ‘Billy Bob Thornton’ ). Clicking the button executes my tag write and closes the popup. It doesn’t matter what I put in the script for the popup id, it closes.