# Clicking on Menu Tree item runs a script

**URL:** <https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636>\
**Category:** Ignition Early Access\
**Created:** [September 28, 2019, 12:26pm UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636 "2019-09-28T12:26:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 28, 2019, 12:26pm UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/1 "2019-09-28T12:26:41Z")

</div>

Hi  
I want when I click on menu tree item instead of opening a page it run python script.  
How should I do that?

---

<div class="post-metadata">

**Author:** ![jball](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jball/32/11128_2.png) [@jball](https://forum.inductiveautomation.com/u/jball)\
**Post date:** [September 30, 2019, 4:58pm UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/2 "2019-09-30T16:58:57Z")

</div>

Hi @nader.chinichian, there is a component event called `onItemClicked` where you can run a script based on what was clicked. You’ll just need to filter the the items by label or something similar:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6a41afed4930ef2a95586ae599e533937698b97f.png)

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 30, 2019, 5:14pm UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/3 "2019-09-30T17:14:09Z")

</div>

Thansks Joshua,  
By the way so if I want to open my main view I have to use script or is there another way to do that? I mean I cant find any property for opening view on Menu Tree. There is only property for opening page.

---

<div class="post-metadata">

**Author:** ![jball](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jball/32/11128_2.png) [@jball](https://forum.inductiveautomation.com/u/jball)\
**Post date:** [September 30, 2019, 6:01pm UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/4 "2019-09-30T18:01:33Z")

</div>

No prob! If your main view is setup via a **Page Configuration** path (shown below), you can assign that path to the `target` property of a menu item and that view will be shown. If you're looking to do something semi custom like a popup or displaying a view that isn't bound to a path, you'll need to do that via script. In that case, just leave the `target` property blank for the menu item that you want to trigger this behavior, and use the script.

### Perspectives Page Configuration

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/55e3ed4d75b633078b3d57fffeef4990da896c3a.png)

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [November 2, 2019, 5:23am UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/5 "2019-11-02T05:23:19Z")

</div>

Hi  
If I have some sub item menu and need to password protect them in the parent Item, How can I do this?  
I can setup check password on Parent Item onItemClicked like you said and open page manually but how can I force it to go to sub menu?

---

<div class="post-metadata">

**Author:** ![jball](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jball/32/11128_2.png) [@jball](https://forum.inductiveautomation.com/u/jball)\
**Post date:** [November 6, 2019, 9:01pm UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/6 "2019-11-06T21:01:46Z")

</div>

I think you might be better off using a script that would conditionally create the child `items` based on the password check. That way they just don’t exist until that check has been met. Alternatively, you could enable/disable menu items based on the password check, if that would work for your use case.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [November 7, 2019, 9:59am UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/7 "2019-11-07T09:59:47Z")

</div>

Thanks. good idea.  
for your second one, where the props for enable disable menu item?

---

<div class="post-metadata">

**Author:** ![jball](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jball/32/11128_2.png) [@jball](https://forum.inductiveautomation.com/u/jball)\
**Post date:** [November 7, 2019, 5:43pm UTC](https://forum.inductiveautomation.com/t/clicking-on-menu-tree-item-runs-a-script/28636/8 "2019-11-07T17:43:45Z")

</div>

Each menu item has an `enabled` property that allows it to be actionable. If set to false, the menu item won’t open child items or navigate to a destination.
