# Scripting on a template instance

**URL:** <https://forum.inductiveautomation.com/t/scripting-on-a-template-instance/10543>\
**Category:** Ignition\
**Created:** [September 29, 2015, 12:49pm UTC](https://forum.inductiveautomation.com/t/scripting-on-a-template-instance/10543 "2015-09-29T12:49:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AleInge](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@AleInge](https://forum.inductiveautomation.com/u/AleInge)\
**Post date:** [September 29, 2015, 12:49pm UTC](https://forum.inductiveautomation.com/t/scripting-on-a-template-instance/10543/1 "2015-09-29T12:49:40Z")

</div>

Hi,

I’m struggling with my first SCADA project and I am in trouble with defining an event script on a template instance. I’ve realized a simple template (a label with some minor graphical elements such as lines, squares, etc.) to use as button for the menu of my main window and after creating an instance of such template, I configure on it a mouse click event to swap to the designated page, but it seems to don’t get the mouse event and thus no swapping occour… ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

I could add the event directly on the label in the template and use a template parameter to pass the correct window name to the instance, but I would avoid this because I’d prefer to define a script on each instance (more handy): how can I do this?

Thank you!  
Regards,

Alessandro

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 29, 2015, 1:04pm UTC](https://forum.inductiveautomation.com/t/scripting-on-a-template-instance/10543/2 "2015-09-29T13:04:20Z")

</div>

How have you implemented the mouse click event? I created a simple template, placed it on a window, right-clicked it and chose Scripting, then put a simple script under mouseClicked and it works fine.

---

<div class="post-metadata">

**Author:** ![AleInge](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@AleInge](https://forum.inductiveautomation.com/u/AleInge)\
**Post date:** [September 29, 2015, 2:17pm UTC](https://forum.inductiveautomation.com/t/scripting-on-a-template-instance/10543/3 "2015-09-29T14:17:06Z")

</div>

Hi, I right-clicked on the instance then selected “scripting”. I tryed to use both the “navigation” panel and the script editor (adding a simple print) but it didn’t work (and no errors are prompted…).

After your reply I tryed to create a new template with the same elements and now it seems to work fine… I can’t figure what happened… 😊

Thank you for your reply,

Alessandro

---

<div class="post-metadata">

**Author:** ![mm3](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mm3](https://forum.inductiveautomation.com/u/mm3)\
**Post date:** [September 29, 2015, 3:21pm UTC](https://forum.inductiveautomation.com/t/scripting-on-a-template-instance/10543/4 "2015-09-29T15:21:22Z")

</div>

For future reference:  
You might have layered some of the graphical elements (squares) on top of the button. I would select your button and choose ‘Bring to Front’ to make sure it’s z order is on top.
