# onShutdown Script for Docked View

**URL:** <https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 5, 2022, 2:53pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720 "2022-08-05T14:53:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob.ramirez](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jacob.ramirez](https://forum.inductiveautomation.com/u/jacob.ramirez)\
**Post date:** [August 5, 2022, 2:53pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/1 "2022-08-05T14:53:20Z")

</div>

I have a script that sets a property on the window and then writes to the logger so I can make sure it runs.  
The script is on a view’s onShutdown event.  
Every time the docked view closes (or toggles) the script does not run.  
I have an “X” label on the screen that calls the toggle dock script and then when you click out of the dock, it closes as well.

When I close the screen from the designer the script runs but from a perspective session it does not.

Does anyone else see this kind of behavior?

---

<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:** [August 5, 2022, 3:01pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/2 "2022-08-05T15:01:43Z")

</div>

When you close the View in the Designer, you’re closing the resource and it’s no longer “live”. When you _collapse_ a Docked View, it only slides out of view on the web page - it is not removed from the DOM, and you’ll find that everything in the Docked View is still working and executing just out of sight. As such, the onShutdown Event will not execute.

---

<div class="post-metadata">

**Author:** ![jacob.ramirez](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jacob.ramirez](https://forum.inductiveautomation.com/u/jacob.ramirez)\
**Post date:** [August 5, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/3 "2022-08-05T15:05:18Z")

</div>

I need to set a root custom property value back to a default value when the docked view closes. If the onShutdown event won’t execute, do you have a suggestion on how I can achieve this?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [August 5, 2022, 3:36pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/4 "2022-08-05T15:36:15Z")

</div>

send a message when you open the dock.

I use this typically:  
Edit: note this is typically in a button action that is calling the dock.

```auto
	dockId = 'dockNewProject'
	payload = {'dockId':dockId}
	system.perspective.sendMessage('msgCleanDock',payload=payload)
	system.perspective.openDock(id=dockId)

```

Then the dock has a message handler on it called msgCleanDock, and a parameter called dockId.  
The message handler looks something like this:

```auto
	dockId = payload.get('dockId')
	if dockId == self.view.params.dockId:
		#Clean this dock
		pass

```

---

<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:** [August 5, 2022, 3:36pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/5 "2022-08-05T15:36:32Z")

</div>

If you’re using the default handles to expand/collapse the docked view, then you won’t be able to do this because the Docked View has no insight into whether it is expanded or collapsed, or even when that change occurs. You could implement your own buttons to manage the expanding and collapsing, but this would require a new UI piece (probably a button) in your primary view, and you’d need to guarantee the UI isn’t covered by the Docked View.

The new button would require a session property (to manage state of your property).

onClick of the expand/collapse button:

```auto
system.perspective.toggleDock("DockID")
self.session.custom.dock_root_custom_prop = "Default Value"

```

Your custom prop would then need to be bidirectionally bound against the session proeprty.

You could also manage this with message handlers, but it gets even more complicated.

---

<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:** [August 5, 2022, 3:37pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/6 "2022-08-05T15:37:43Z")

</div>

@bschroeder , The problem with this approach is you still need a way to trigger the Handlers; the built-in dock handles will not trigger this script.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [August 5, 2022, 3:39pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/7 "2022-08-05T15:39:10Z")

</div>

That code is run from a button action. I don’t usually use the dock action. So I script all my dock actions through a button. So open dock and send message. Seems to work well on my end.

---

<div class="post-metadata">

**Author:** ![jacob.ramirez](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jacob.ramirez](https://forum.inductiveautomation.com/u/jacob.ramirez)\
**Post date:** [August 5, 2022, 3:41pm UTC](https://forum.inductiveautomation.com/t/onshutdown-script-for-docked-view/62720/8 "2022-08-05T15:41:21Z")

</div>

Thanks for the suggestion. I like this approach.  
I’ll call a message handler when I open the dock.  
The message handler that is on the dock will do the action I need to do.
