# Add items to menu tree from script

**URL:** <https://forum.inductiveautomation.com/t/add-items-to-menu-tree-from-script/77012>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [July 27, 2023, 2:09pm UTC](https://forum.inductiveautomation.com/t/add-items-to-menu-tree-from-script/77012 "2023-07-27T14:09:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Callulier](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@Pierre\_Callulier](https://forum.inductiveautomation.com/u/Pierre_Callulier)\
**Post date:** [July 27, 2023, 2:09pm UTC](https://forum.inductiveautomation.com/t/add-items-to-menu-tree-from-script/77012/1 "2023-07-27T14:09:40Z")

</div>

Hi,  
I've some trouble adding items to a menu tree with scrip.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/5/d549a717c6887c5c6af149bb413c9e9626f7351e.png)

I'd like to add items with a script when a new MQTT edge nodes appear in my MQTT engine tag provider.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/067e6f80896d3d5f006ddd2a79014e9939689fcf.png)

Is there first a simple way to add items to a menu tree with a event script ??

---

<div class="post-metadata">

**Author:** ![franklepkowski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/franklepkowski/32/4808_2.png) [@franklepkowski](https://forum.inductiveautomation.com/u/franklepkowski)\
**Post date:** [July 27, 2023, 3:22pm UTC](https://forum.inductiveautomation.com/t/add-items-to-menu-tree-from-script/77012/2 "2023-07-27T15:22:10Z")

</div>

Hello. I would leverage a timed event script on the gateway to handle this. It would give more predictable cadence than a tag change on a folder which can execute on quality, timestamp,value changes, etc.

See this code below, I think it will get you started.

```auto
item = {
				  "target": "",
				  "items": [],
				  "navIcon": {
				    "path": ""
				  },
				  "label": {
				    "text": "",
				    "icon": {
				      "path": "material/lens",
				      "style": {
				        "classes": "B_Labels/Navigation/AlarmOff"
				      }
				    }
				  },
				  "visible": True,
				  "enabled": True,
				  "showHeader": False,
				  "resetOnClick": False,
				  "backActionText": "",
				  "style": {
				    "classes": "B_Labels/Navigation/BackgroundUnselected"
				  }
				}
			newitem = item
			newitem['enabled'] = your_data
			newitem['label']['text'] = your_data
		
			self.getChild("MenuTree").props.items.append(newitem)

```

Regards,

Frank

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 27, 2023, 5:09pm UTC](https://forum.inductiveautomation.com/t/add-items-to-menu-tree-from-script/77012/3 "2023-07-27T17:09:41Z")

</div>

Is there a reason you're not using the Tag Browse Tree component?
