# Virtually pressing button to run code

**URL:** <https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200>\
**Category:** Ignition\
**Created:** [October 21, 2014, 2:30pm UTC](https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200 "2014-10-21T14:30:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronkneeland](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@aaronkneeland](https://forum.inductiveautomation.com/u/aaronkneeland)\
**Post date:** [October 21, 2014, 2:30pm UTC](https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200/1 "2014-10-21T14:30:32Z")

</div>

I have a button that contains a great deal of code and custom properties so I would prefer not to re-write it all. Is there a way to programmatically ‘press’ the button to execute the code in the “Action Performed” event handler?

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [October 21, 2014, 2:38pm UTC](https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200/2 "2014-10-21T14:38:48Z")

</div>

try:

```auto
event.source.parent.getComponent("Button").doClick()
```

---

<div class="post-metadata">

**Author:** ![aaronkneeland](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@aaronkneeland](https://forum.inductiveautomation.com/u/aaronkneeland)\
**Post date:** [October 21, 2014, 2:54pm UTC](https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200/3 "2014-10-21T14:54:08Z")

</div>

This did not seem to work. I am trying to do this in the extension function onCellEdited in a power table. Here is the code. No errors just no DB updates.

```auto
import system
self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)
event.source.parent.getComponent('btnHome 6').doClick()
```

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [October 21, 2014, 3:28pm UTC](https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200/4 "2014-10-21T15:28:42Z")

</div>

My preferred method of handling this situation is to put the script in a timer with an initial delay of 0.

Then you can start the timer from your button’s action performed event and also from anywhere else you want.

You can copy and paste the script into the timer but you will probably need to correct some references.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [October 21, 2014, 3:34pm UTC](https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200/5 "2014-10-21T15:34:31Z")

</div>

Try this:

```auto
import system
self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)
self.parent.getComponent('btnHome 6').doClick()
```

Best,

---

<div class="post-metadata">

**Author:** ![aaronkneeland](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@aaronkneeland](https://forum.inductiveautomation.com/u/aaronkneeland)\
**Post date:** [October 21, 2014, 6:23pm UTC](https://forum.inductiveautomation.com/t/virtually-pressing-button-to-run-code/9200/6 "2014-10-21T18:23:56Z")

</div>

Worked perfectly. Thank you!
