# Run component A event from component B event

**URL:** <https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925>\
**Category:** Ignition\
**Created:** [January 8, 2024, 4:25pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925 "2024-01-08T16:25:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [January 8, 2024, 4:25pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/1 "2024-01-08T16:25:31Z")

</div>

Is there a way to script a button to run the onClick mouse event script of a different component when the button is clicked??

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 8, 2024, 4:27pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/2 "2024-01-08T16:27:18Z")

</div>

Classic mistake.

Put the logic into a function in a script module and then call that function any time you need it.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [January 8, 2024, 4:31pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/3 "2024-01-08T16:31:54Z")

</div>

Yes but what if the logic involves altering props of components. Like I have a label that does this when clicked: `def runAction(self, event):

```auto
def runAction(self, event):
	# Clear table 
	self.getSibling('Samples').props.selection.selectedRow = -1
	self.getSibling('Samples').props.selection.selectedColumn = -1
	self.getSibling('Samples').props.selection.selectedRow = None
	self.getSibling('Samples').props.selection.selectedColumn = None
	
	# Clear dropdowns
	self.getSibling('ScheduleTypeDropdown').props.value = 0
	
	# Clear entry fields
	self.getSibling('IntervalEntryField').props.value = 0
	self.getSibling('OffsetEntryField').props.value = 0
	
	# Clear labels
	self.getSibling('StatusLBL').props.text = ""
	

```

I have a button as well that is going to close the popup. Instead of copying and pasting that code I didnt know if I could just trigger it in a one liner.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 8, 2024, 4:36pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/4 "2024-01-08T16:36:20Z")

</div>

Put a custom method on the highest level container that contains all your components and invoke it (ideally indirectly using messaging).

Strongly consider separating the UI update portions of your scripts from any "business logic" (put something in the DB, update X tags, etc), which should reside in functionally pure scripts in the project library.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [January 8, 2024, 4:37pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/5 "2024-01-08T16:37:12Z")

</div>

You could also consider "lifting" this logic up to a custom method (defined on, let's say, the root window).

 ![SCR-20240108-jrsj](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/01f6dd57846ef0ed32731f708a202281b0ea6ff5.png)

You could then invoke this "local" shared method from other components in your view.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 8, 2024, 4:37pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/6 "2024-01-08T16:37:53Z")

</div>

Or, in the specific example you posted, just broadcast a "clear" message and have each component implement a handler that clears itself. Then you can add and remove components more easily.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [January 8, 2024, 4:41pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/7 "2024-01-08T16:41:12Z")

</div>

Ok thanks

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [January 8, 2024, 4:43pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/8 "2024-01-08T16:43:56Z")

</div>

I like this way. How do you call one of these custom methods ??

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [January 8, 2024, 5:07pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/9 "2024-01-08T17:07:03Z")

</div>

There is some guidance [here](https://docs.inductiveautomation.com/display/DOC81/Perspective+Component+Methods#PerspectiveComponentMethods-CustomMethods) on Perspective Custom Methods (there are matching constructs in Vision too, fwiw).

A basic example is shown below (and pictures are nice, so... 😁):

 ![SCR-20240108-kckm](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/8/9897a1eb440e08955f6a7e12595354c82d7e44a4.png)

 ![SCR-20240108-kcsy](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e42d71415c31b136eee37044417e571ceef611b1.jpeg)

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [January 8, 2024, 5:07pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/10 "2024-01-08T17:07:46Z")

</div>

Beautiful. Happy Monday

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 12, 2024, 3:04pm UTC](https://forum.inductiveautomation.com/t/run-component-a-event-from-component-b-event/83925/12 "2024-01-12T15:04:09Z")

</div>

> [@cesma2000](#):
>
> insuppose you can implement a msgHandlaer tomdo that.

@Welcome back, @cesma2000. Is this a question, a comment, an answer or gobbledygook? There's an edit button (pencil icon) below your post to clean it up.
