# Perspective: How to send function definitions to a docked View to use on button calls?

**URL:** <https://forum.inductiveautomation.com/t/perspective-how-to-send-function-definitions-to-a-docked-view-to-use-on-button-calls/42780>\
**Category:** Ignition\
**Created:** [January 30, 2021, 12:57pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-send-function-definitions-to-a-docked-view-to-use-on-button-calls/42780 "2021-01-30T12:57:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 30, 2021, 12:57pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-send-function-definitions-to-a-docked-view-to-use-on-button-calls/42780/1 "2021-01-30T12:57:40Z")

</div>

How can I send function definitions to a docked view, which buttons in the docked view would then call? I have tried using sendMessage to send the functions within the payload and then write these to functions defined on the root container, but I get this error:  
`AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'onCancel'`  
I assume I can’t just overwrite a function definition by setting it to another function definition…

In Vision, I do this for my custom ‘confirm action’ popup window in order to allow the designer to customise what happens when the confirm or cancel buttons are pressed. I use the Window method `putClientProperty` to add a function to the Window. How would I do this in Perspective?

```auto
def confirmAction(event, message, fnOnYes, fnOnNo=None, yesLabel='Yes', noLabel='No', heading="Confirm Action"):
	'''
    Prerequisites:
        - Requires the ppuConfirmAction popup
        
	Usage:
	# Example code to place on a button
tagPrefix = 'tagPath'

def fnOnYes():
	system.tag.write(tagPrefix + '/YesPB', 1)
def fnOnNo():
	#actions on no, otherwise can remove this function

title = 'Confirm Reset Flow Totaliser'
message = 'This will reset the runtime hours. Are you sure?'
shared.util.gui.confirmAction(event, message, fnOnYes, fnOnNo)
	'''	
	window = system.nav.openWindow('Popups/ppuConfirmAction', {'_message':message, '_yesLabel':yesLabel, '_noLabel':noLabel, '_heading':heading})
	system.nav.centerWindow(window)
	
	window.putClientProperty('functionOnYes', fnOnYes)
	window.putClientProperty('functionOnNo', fnOnNo)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 30, 2021, 2:40pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-send-function-definitions-to-a-docked-view-to-use-on-button-calls/42780/2 "2021-01-30T14:40:29Z")

</div>

I’m not sure you can. `.putClientProperty()` is a feature of Vision simply because Vision is built on top of Swing. Perspective isn’t built on top of a technology that offers arbitrary customizations like that. You might be able to assign to a custom view property of type Object…

A quick review of the SDK API doesn’t show any obvious way to do what you are trying.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 30, 2021, 2:44pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-send-function-definitions-to-a-docked-view-to-use-on-button-calls/42780/3 "2021-01-30T14:44:32Z")

</div>

> [@pturmel](#):
>
> You might be able to assign to a custom view property of type Object

I did try this, but it just comes back as a unicode string, something like `<function onConfirm 0x40>`

Would this be something that a custom module could provide a function for?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 30, 2021, 4:05pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-send-function-definitions-to-a-docked-view-to-use-on-button-calls/42780/4 "2021-01-30T16:05:26Z")

</div>

Probably not. It would have to be a change to the implementation of `ViewModel` or a related class, which only IA could do. (Unless something I’ve not seen in the API would apply.)

---

<div class="post-metadata">

**Author:** ![Dan\_Bridgeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dan_bridgeman/32/3610_2.png) [@Dan\_Bridgeman](https://forum.inductiveautomation.com/u/Dan_Bridgeman)\
**Post date:** [January 30, 2021, 7:26pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-send-function-definitions-to-a-docked-view-to-use-on-button-calls/42780/5 "2021-01-30T19:26:13Z")

</div>

We’ve found that doing it the other way round has worked well for us. This is with embedded views instead of docked ones, but I think the same principle should hold.

We have a function menu view which takes an array of “buttons” as an input parameter. The parent view which needs a function menu embeds it and defines the buttons it needs.

Each button is opened up in its own embedded view within the function menu view, which contains a single button and has input parameters for key and label. When a user presses the button (or presses the defined hotkey) the script just calls

```auto
system.perspective.sendMessage("pressedFunctionMenuButton", payload=self.view.params.key, scope = "page")

```

Back on the parent view which contains the function menu, we define a message handler which receives the message and then executes the appropriate function.
