# Back action in MenuTree

**URL:** <https://forum.inductiveautomation.com/t/back-action-in-menutree/84567>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 22, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567 "2024-01-22T13:21:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![amolinse](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@amolinse](https://forum.inductiveautomation.com/u/amolinse)\
**Post date:** [January 22, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/1 "2024-01-22T13:21:07Z")

</div>

Is it possible to write a script in back action in a MenuTree?  
I wrote a script that write the selected path in a custom property, but I would like that if the user press the back button the last item selected is removed from the path. I wrote my script in event onItemClicked but it seems that the back button doesn't react to this script and I cannot find any property in MenuTree that changes when back button is pressed.  
Any idea?

---

<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:** [January 22, 2024, 3:56pm UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/2 "2024-01-22T15:56:48Z")

</div>

Yes, in a roundabout way.

You need to actually supply a dummy item within the items list for the item, and then you need to use the `onItemClicked` script to invoke the [back](https://docs.inductiveautomation.com/display/DOC81/system.perspective.navigateBack) function by checking to see if your "back" item was the one clicked.

---

<div class="post-metadata">

**Author:** ![amolinse](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@amolinse](https://forum.inductiveautomation.com/u/amolinse)\
**Post date:** [January 23, 2024, 8:15am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/3 "2024-01-23T08:15:20Z")

</div>

Thanks for help, but I have still problems with this solution. On the top of the menu tree the back arrow is still showing, I cannot be sure that users don't press this arrow instead of the dummy item.

---

<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:** [January 23, 2024, 10:00am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/4 "2024-01-23T10:00:48Z")

</div>

Add this in the advanced stylesheet:

```css
.menu-back-action {
    display: none !important;
}

```

---

<div class="post-metadata">

**Author:** ![amolinse](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@amolinse](https://forum.inductiveautomation.com/u/amolinse)\
**Post date:** [January 23, 2024, 10:41am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/5 "2024-01-23T10:41:24Z")

</div>

Thanks! I didn't think to hide it using styles, but it works perfect.

---

<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:** [January 23, 2024, 10:47am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/6 "2024-01-23T10:47:32Z")

</div>

Keep in mind that hiding things with css is only client side and people can "unhide" them with the dev tools integrated to their browsers.

---

<div class="post-metadata">

**Author:** ![amolinse](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@amolinse](https://forum.inductiveautomation.com/u/amolinse)\
**Post date:** [January 23, 2024, 10:48am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/7 "2024-01-23T10:48:14Z")

</div>

I don't really get how this navigateBack works in a menuTree. I'm adding a dummy item as the first element in the list, but I don't understand how to write the right code onItemClicked. So far I wrote this script that it is not working:

```auto
path = event["path"]
if len(path)>1:
	if path[1]==0:
		system.perspective.navigateBack()
		a = path.pop()
self.custom.path = path

```

---

<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:** [January 23, 2024, 10:51am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/8 "2024-01-23T10:51:28Z")

</div>

Well actually... I don't think `navigateBack` does exactly the same thing as the back button.

Let's take a few steps back: What's your end goal here ?

---

<div class="post-metadata">

**Author:** ![amolinse](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@amolinse](https://forum.inductiveautomation.com/u/amolinse)\
**Post date:** [January 23, 2024, 11:14am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/9 "2024-01-23T11:14:30Z")

</div>

My idea is to have 3 levels in the menuTree: department -\> machine -\> position (possible path [0,0,1]). When I choose position I change background for the selected position, for user to know which position is selected. But it is possible that the user regrets and wants to choose a position in another machine, so I need a back button to choose another machine (this was working well with the back button, problem here was that if I chose same machine the old selected position was remaining selected).  
A half solution is to select for the dummy item the option resetOnClick, but it is sending me back to department not to machine level.

---

<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:** [January 23, 2024, 11:24am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/10 "2024-01-23T11:24:26Z")

</div>

How do you know you're in the "position" menu ? Do you store a path ?  
And how do you apply the background color ? Is the color the same for both "department" and "machine" menus ?

---

<div class="post-metadata">

**Author:** ![amolinse](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@amolinse](https://forum.inductiveautomation.com/u/amolinse)\
**Post date:** [January 23, 2024, 11:54am UTC](https://forum.inductiveautomation.com/t/back-action-in-menutree/84567/11 "2024-01-23T11:54:22Z")

</div>

yes in my last script yo can see that in last line I'm saving the event path in a custom property. I have a change script on this property to change background:

```auto
if length>=3:
	department = path[0].value
	machine = path[1].value
	position = path[2].value
	items = self.props.items[department].items[machine].items
	
	for i,item in enumerate(items):
		if i>0:
			if i == position:
				item["style"]["classes"] = "foqus/item_selected"
				#system.perspective.print(classes)
			else:
				item["style"]["classes"] = ""

```

Machine and department have the same background, as they open a new list of items I don't need to distinguish them.  
My idea was to remove from the path last element in list if I was pressing the button back so I could control the event and set all position with same background
