# Trigger the click event of the button by another button

**URL:** <https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [March 14, 2023, 8:55am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013 "2023-03-14T08:55:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![saravanan\_Manickam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@saravanan\_Manickam](https://forum.inductiveautomation.com/u/saravanan_Manickam)\
**Post date:** [March 14, 2023, 8:55am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/1 "2023-03-14T08:55:22Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/293c4615e0e106a33d1961daa36c62b882668f9e.png)  
Here I have a button in bottom as Dock.  
By using that button I need to trigger the click event of the above Button - 1.  
Please suggest some Idea..  
--NOTE : here the button was inside the column container , but in another view it may in Tab container or outside of the container.  
Thanks in advance

---

<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:** [March 14, 2023, 9:15am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/2 "2023-03-14T09:15:36Z")

</div>

Generally you cannot. Move the logic to a project script function and call that from both buttons.

---

<div class="post-metadata">

**Author:** ![saravanan\_Manickam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@saravanan\_Manickam](https://forum.inductiveautomation.com/u/saravanan_Manickam)\
**Post date:** [March 14, 2023, 9:50am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/3 "2023-03-14T09:50:52Z")

</div>

😟 the button in the bottom of the view as docked but the above button-1 may differ as I mentioned in the **NOTE**..EX : I may have a 397+ views

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 14, 2023, 3:17pm UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/4 "2023-03-14T15:17:57Z")

</div>

Why does that matter? @pturmel's suggestion would still work. The only reason to call another components event is to execute the code that would be executed by that event.

If instead you abstract that code to a project script function which both components can reach, then they can both execute the same code with out knowing about each other. Doesn't matter if there are two components or 397+ components.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [March 14, 2023, 3:37pm UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/5 "2023-03-14T15:37:17Z")

</div>

Move your logic into focusGained.  
Then send a perspective message and trigger it with self.focus()

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 14, 2023, 3:41pm UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/6 "2023-03-14T15:41:36Z")

</div>

How do you prevent the code from executing when the focus is gained unintentionally?

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [March 14, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/7 "2023-03-14T15:42:16Z")

</div>

you can't

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 14, 2023, 3:47pm UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/8 "2023-03-14T15:47:04Z")

</div>

My guess is a big coupling of the GUI and business logic

---

<div class="post-metadata">

**Author:** ![saravanan\_Manickam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@saravanan\_Manickam](https://forum.inductiveautomation.com/u/saravanan_Manickam)\
**Post date:** [March 17, 2023, 5:49am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/9 "2023-03-17T05:49:12Z")

</div>

1. Is it possible to find the component path.

EX : let's consider the button 1 as in the name of " btn\_save". by writing any scripting by python to find the path of the component is it possible..

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [March 17, 2023, 10:20am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/10 "2023-03-17T10:20:29Z")

</div>

Will the button always be on the screen or not?

Ifso then i guess in theory you could look for it with js. But its terrible practice tbh

Well i guess if you like want the save button to be able to "float" on every page without having to scroll down... it wouldnt be to bad.

You'll have to **give every button a domId in the metadata** with the same name (btn\_Save)  
and be sure there will never be multiple on the same screen (else it might trigger the wrong one)

i'll get you the js script a bit later

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 17, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/11 "2023-03-17T13:03:18Z")

</div>

Is there any reason you wouldn't just do what Phil suggested ?  
What problem are you trying to solve ?

---

<div class="post-metadata">

**Author:** ![j.israelsen](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@j.israelsen](https://forum.inductiveautomation.com/u/j.israelsen)\
**Post date:** [March 17, 2023, 1:43pm UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/12 "2023-03-17T13:43:45Z")

</div>

What Phil suggested would work.

Also, it seems like a message handler would work (assuming you are using Perspective). Here is a link to the documentation:  
[https://docs.inductiveautomation.com/display/DOC81/Component+Message+Handlers](https://docs.inductiveautomation.com/display/DOC81/Component+Message+Handlers)

---

<div class="post-metadata">

**Author:** ![saravanan\_Manickam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@saravanan\_Manickam](https://forum.inductiveautomation.com/u/saravanan_Manickam)\
**Post date:** [March 21, 2023, 4:50am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/13 "2023-03-21T04:50:46Z")

</div>

yes i'm using perspective

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 21, 2023, 6:05am UTC](https://forum.inductiveautomation.com/t/trigger-the-click-event-of-the-button-by-another-button/71013/14 "2023-03-21T06:05:38Z")

</div>

I'm guessing that it may not make sense to put such niche code into a project script in this instance.

For something like this, I would be calling `system.perspective.sendMessage` on your dock button to trigger a message handler on the content View button, like @j.israelsen mentioned.
