# Calling custom method from message handler of the same item

**URL:** <https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483>\
**Category:** Ignition\
**Created:** [June 27, 2024, 5:36pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483 "2024-06-27T17:36:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Espejo](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Javier\_Espejo](https://forum.inductiveautomation.com/u/Javier_Espejo)\
**Post date:** [June 27, 2024, 5:36pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483/1 "2024-06-27T17:36:18Z")

</div>

Could a custom method be called directly from a message handler of the same item?

I'm trying but it doesn't work.

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [June 27, 2024, 5:54pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483/2 "2024-06-27T17:54:04Z")

</div>

How are you trying to call it? Post some code.

---

<div class="post-metadata">

**Author:** ![Javier\_Espejo](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Javier\_Espejo](https://forum.inductiveautomation.com/u/Javier_Espejo)\
**Post date:** [June 27, 2024, 6:02pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483/3 "2024-06-27T18:02:05Z")

</div>

```python
def onMessageReceived(self, payload):

	self.methodOfTheItem()

```

---

<div class="post-metadata">

**Author:** ![Javier\_Espejo](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Javier\_Espejo](https://forum.inductiveautomation.com/u/Javier_Espejo)\
**Post date:** [June 27, 2024, 6:11pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483/4 "2024-06-27T18:11:43Z")

</div>

In the same way, if I call a method of some of the children, the method is not found. Does it have to be a method implemented within the the child "instance"?

ie.

```python
	def onMessageReceived(self, payload):

		item = self.getChild('theItemName')
		item.methodOfTheItem()

```

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [June 27, 2024, 6:44pm UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483/5 "2024-06-27T18:44:16Z")

</div>

> [@Javier\_Espejo](#):
>
> a method implemented within the the child "instance"?

What do you mean by that?

Calling `self.methodOfTheItem()` should work if the custom method _methodOfTheItem()_ is defined on the same component that the message handler is defined on.

---

<div class="post-metadata">

**Author:** ![Javier\_Espejo](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Javier\_Espejo](https://forum.inductiveautomation.com/u/Javier_Espejo)\
**Post date:** [June 28, 2024, 6:43am UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483/6 "2024-06-28T06:43:28Z")

</div>

Basicly, this is the sketch:

 ![mockup views and callings](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e3f2c3d4f918118f3e664e8ed4f97fdb25923b02.png)

In MHReset(), if I print the type of the method to be called:

```
type(self.reset)

```

the result is "\<type 'instancemethod'\>", and just later, the calling ("self.reset()") fails.

---

<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:** [June 28, 2024, 6:57am UTC](https://forum.inductiveautomation.com/t/calling-custom-method-from-message-handler-of-the-same-item/92483/7 "2024-06-28T06:57:47Z")

</div>

This should work as expected. Make sure the scope is properly configured, both in the `sendMessage` call and in the message handler.

If they are, something else is going wrong and you'll need to add logs to find out what.
