# Example of using a custom method

**URL:** <https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883>\
**Category:** Ignition\
**Created:** [January 15, 2019, 8:08am UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883 "2019-01-15T08:08:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esn](https://avatars.discourse-cdn.com/v4/letter/e/91b2a8/32.png) [@Esn](https://forum.inductiveautomation.com/u/Esn)\
**Post date:** [January 15, 2019, 8:08am UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/1 "2019-01-15T08:08:31Z")

</div>

Hi,

Could I get an example or two of how to use the ‘custom method’ in component scripting?  
I can’t seem to grasp how to utilize it.

My goal is to be able to drag-n-drop tags from a tag browser tree into a standard table component.  
The standard table component doesn’t have a ‘onTagsDropped’ extention function like some other compoennts do.  
So I want to add that functionality - possibly through a custom method?

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:** [January 15, 2019, 1:52pm UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/2 "2019-01-15T13:52:12Z")

</div>

Unfortunately, no, that won’t work. Custom methods are conveniences for consolidating code for a component, with a `self` object available for the code, but nothing in Ignition will automatically call them. To implement onTagsDropped for a component that doesn’t natively support it would require a bunch of Java Swing hackery, if doable at all.

---

<div class="post-metadata">

**Author:** ![Esn](https://avatars.discourse-cdn.com/v4/letter/e/91b2a8/32.png) [@Esn](https://forum.inductiveautomation.com/u/Esn)\
**Post date:** [January 16, 2019, 6:02am UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/3 "2019-01-16T06:02:52Z")

</div>

@pturmel Ok, tough luck I guess. Thanks for the reply.

I’m still very interested in seeing a practial example of how to use the custom method though.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 16, 2019, 1:53pm UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/4 "2019-01-16T13:53:44Z")

</div>

Try checking out this [link](https://docs.inductiveautomation.com/display/DOC79/Custom+Component+Methods), there is another link to a video from the page I’m referencing.

---

<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:** [January 16, 2019, 2:11pm UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/5 "2019-01-16T14:11:49Z")

</div>

Probably the most common use of custom methods is to get access to `self` in runScript bindings. I hardly ever use those, as I can do better with my [objectScript()](https://www.automation-pros.com/simaids/doc/expression.objectscript.html) expresssion function (part of the free [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) modules), without needing custom methods.

---

<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 16, 2019, 3:37pm UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/6 "2019-01-16T15:37:42Z")

</div>

> [@Esn](#):
>
> I’m still very interested in seeing a practial example of how to use the custom method though.

One big advantage is separating logic from event handling - ie, if you want a component to do the same thing on key press that it does on right click (for a contrived example) you can just have each event handler call the same custom method, to avoid duplicating logic.

---

<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 16, 2019, 3:40pm UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/7 "2019-01-16T15:40:37Z")

</div>

> [@Esn](#):
>
> My goal is to be able to drag-n-drop tags from a tag browser tree into a standard table component.  
> The standard table component doesn’t have a ‘onTagsDropped’ extention function like some other compoennts do.  
> So I want to add that functionality - possibly through a custom method?

Also, I thought this sounded familiar, so I did a search, and realized that I actually already did this a year ago:

> [@Drag and drop from tag browse tree to power table](http://forum.inductiveautomation.com/t/drag-and-drop-from-tag-browse-tree-to-power-table/15260/3):
>
> Here’s a sample window I came up with a while back. Note that is pretty low-level Java Swing stuff - so you’re on your own merits to figure out how it all works. Also, don’t even try and call into support about this. [Power Table Tags Dropped.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/70c831f665ee8ad4a4167c49a595750bf5859a8b.proj) (19.9 KB) For a brief explanation: The initialize() function of the power table fires the addListener() custom method, which creates an instance of a custom [DropTargetListener](https://docs.oracle.com/javase/7/docs/api/java/awt/dnd/DropTargetListener.html). That custom DropTargetListener has an overridden drop() function…

---

<div class="post-metadata">

**Author:** ![Esn](https://avatars.discourse-cdn.com/v4/letter/e/91b2a8/32.png) [@Esn](https://forum.inductiveautomation.com/u/Esn)\
**Post date:** [January 17, 2019, 7:10am UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/8 "2019-01-17T07:10:35Z")

</div>

@paul-griffith Interesting 🙂 Would you mind sharing the code for your ‘addListener()’ custom method?  
Also to make it work you need the ‘initialize()’ extension function right?

---

<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:** [January 17, 2019, 1:13pm UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/9 "2019-01-17T13:13:57Z")

</div>

Paul _did_ share his code – in the example project.

---

<div class="post-metadata">

**Author:** ![Esn](https://avatars.discourse-cdn.com/v4/letter/e/91b2a8/32.png) [@Esn](https://forum.inductiveautomation.com/u/Esn)\
**Post date:** [January 18, 2019, 7:39am UTC](https://forum.inductiveautomation.com/t/example-of-using-a-custom-method/21883/10 "2019-01-18T07:39:56Z")

</div>

Ah, so he did. I missed that. Thanks.
