# Help with .doClick() function

**URL:** <https://forum.inductiveautomation.com/t/help-with-doclick-function/16235>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 6, 2017, 7:11pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235 "2017-12-06T19:11:34Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![reed.hoffmaster](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@reed.hoffmaster](https://forum.inductiveautomation.com/u/reed.hoffmaster)\
**Post date:** [December 6, 2017, 7:11pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/1 "2017-12-06T19:11:34Z")

</div>

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?

```auto
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!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 7:15pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/2 "2017-12-06T19:15:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![reed.hoffmaster](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@reed.hoffmaster](https://forum.inductiveautomation.com/u/reed.hoffmaster)\
**Post date:** [December 6, 2017, 7:19pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/3 "2017-12-06T19:19:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 7:25pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/4 "2017-12-06T19:25:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 7:30pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/5 "2017-12-06T19:30:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![reed.hoffmaster](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@reed.hoffmaster](https://forum.inductiveautomation.com/u/reed.hoffmaster)\
**Post date:** [December 6, 2017, 7:32pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/6 "2017-12-06T19:32:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 7:35pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/7 "2017-12-06T19:35:15Z")

</div>

Like so:

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

```

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

---

<div class="post-metadata">

**Author:** ![reed.hoffmaster](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@reed.hoffmaster](https://forum.inductiveautomation.com/u/reed.hoffmaster)\
**Post date:** [December 6, 2017, 7:38pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/8 "2017-12-06T19:38:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 7:41pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/9 "2017-12-06T19:41:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![reed.hoffmaster](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@reed.hoffmaster](https://forum.inductiveautomation.com/u/reed.hoffmaster)\
**Post date:** [December 6, 2017, 8:02pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/10 "2017-12-06T20:02:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 8:06pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/11 "2017-12-06T20:06:50Z")

</div>

> [@reed.hoffmaster](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![reed.hoffmaster](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@reed.hoffmaster](https://forum.inductiveautomation.com/u/reed.hoffmaster)\
**Post date:** [December 6, 2017, 8:57pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/12 "2017-12-06T20:57:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 9:00pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/13 "2017-12-06T21:00:17Z")

</div>

Hmph. Out of ideas for you.

---

<div class="post-metadata">

**Author:** ![reed.hoffmaster](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@reed.hoffmaster](https://forum.inductiveautomation.com/u/reed.hoffmaster)\
**Post date:** [December 6, 2017, 9:03pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/14 "2017-12-06T21:03:23Z")

</div>

Well I appreciate it anyway. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 9:22pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/15 "2017-12-06T21:22:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [December 6, 2017, 9:23pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/16 "2017-12-06T21:23:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2017, 9:26pm UTC](https://forum.inductiveautomation.com/t/help-with-doclick-function/16235/17 "2017-12-06T21:26:32Z")

</div>

> [@chi](#):
>
> You'll have to get a reference to your window first.

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