Help with .doClick() function

Hello (Running 7.9)

I am trying to click a button from the Tag Events, Value Changed script section. For some reason I cannon get by button to click. The first action (swapTo) is being performed properly, but not the second. I am also not getting any errors. What am I missing?

system.nav.swapTo('NGV Labels')
event.source.parent.getComponent('Print').doClick()

The button I am trying to click will always be on the window that is currently selected. Do I need to run this script form somewhere else?

Thanks!

That event happens in the gateway, not in a client. You’ll have to use a project Tag Change Script. Look in the “Project”, “Scripts”, “Client Event Scripts” dialog.

I’ve moved the script to the Tag Change section and have attached the desired tag to it but still nothing. Does this need to be a gateway tag as well?

Whoops. This must be a client tag, as the swap works. How did you define doClick()?

Duh. doClick() is built in. However, I don’t see anything that ensures that tag events happen on the foreground thread. Try using invokeLater() to run the doClick() method.

What would that look like? If you don’t mind. Does this go after or before the .doClick() line?

Like so:

system.util.invokeLater(event.source.parent.getComponent('Print').doClick)

Note the lack of parentheses on doClick itself in this usage.

Okay, so what is the invokeLater function doing in this case since there is no specified amount of time?

It puts the given callable (function or method) on the foreground thread’s event queue for immediate execution. In Swing, that thread is called the “Event Dispatch Thread”, and is the only thread allowed to interact with GUI components.

I’m still not getting any action out of this script in the Tag Change section. What is the difference between running script here as apposed to running it on the Tag Even, Value Changed section?

For a Client tag, nothing.
Next possibility:
Which event on your button contains your printing code? I believe doClick() will only work with the actionPerformed event, as there’s no actual mouse events generated.

Yep that’s where the script is on the button. It’s a print button that sends reports to a specific printer, then clears a bunch of client tags. The button functions correctly as well, I just want to automate it’s functions.

Hmph. Out of ideas for you.

Well I appreciate it anyway. Thanks for the help!

Consider moving the contents of the actionPerformed script to a function in a project script module and calling it from both places.

I’m a little surprised that you don’t get an error when using event.source.parent...
In a tag change script, the event source is a tag, not a window. You’ll have to get a reference to your window first.

Heh. Completely missed that. The swapTo returns the window object.