# Accessing Scripting on Window or Root Container from compent

**URL:** <https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834>\
**Category:** Ignition\
**Created:** [June 20, 2016, 9:15pm UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834 "2016-06-20T21:15:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 20, 2016, 9:15pm UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834/1 "2016-06-20T21:15:07Z")

</div>

I have a pop-up window that has a custom method (let’s say it’s called foo) and when a user clicks on a component, I want to call foo. For the life of me I can’t find any documentation on how to reference various scripting objects. I’ve watched the help videos but they discuss very basic issues such as referencing a function on the same object that calls it. They mention putting methods on the main template window, but then do not mention how to call them after that.

So how does one reference a custom method higher up the ladder? Conversely, can one reference a custom method on an component from the window (such as the internalFramActivated script)?

Edit: I’m trying to call the window script this way:

```auto
event.source.parent.Foo()
```

and I get an error message

`Traceback (most recent call last):
  File "<event:mouseReleased>", line 1, in <module>
TypeError: 'unicode' object is not callable`

---

<div class="post-metadata">

**Author:** ![ks0](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ks0/32/6813_2.png) [@ks0](https://forum.inductiveautomation.com/u/ks0)\
**Post date:** [June 20, 2016, 9:42pm UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834/2 "2016-06-20T21:42:55Z")

</div>

If you want to create a method to access from various places, it’s best to put it in the script library. And then just call it every time you want to use it.

```auto
project.scripts.method()
```

---

<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:** [June 20, 2016, 10:14pm UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834/3 "2016-06-20T22:14:44Z")

</div>

My reply to CHH in [this topic](https://inductiveautomation.com/forum/viewtopic.php?f=70&t=15812) might help you.

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 20, 2016, 11:09pm UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834/4 "2016-06-20T23:09:45Z")

</div>

[quote="CHH"]If you want to create a method to access from various places, it's best to put it in the script library. And then just call it every time you want to use it.

```auto
project.scripts.method()
```

It's a good idea, but would overly complicate things. I just need to run the script on the window itself. Honestly, I think I understand enough to just put it on the component and execute it when the window opens, but at the point I want to understand how to do it the original way I planned.

> [@pturmel](#):
>
> My reply to CHH in [this topic](https://inductiveautomation.com/forum/viewtopic.php?f=70&t=15812) might help you.

Thanks that helps to more fully define what I'm working with, but I still can't access the method on the root container. I tried using getRootContainer(), but maybe I'm executing it at the wrong time because it throws an error saying no such method exists for the level I'm calling it at.

Is it possible to access a custom method on the root container from a component within the container?

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 21, 2016, 12:53am UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834/5 "2016-06-21T00:53:34Z")

</div>

Well, I worked it out and found an extremely weird issue. First off, here’s the answer to my question, I found 2 ways of calling the script, foo(), on the root container by clicking on a component (I was using a pop-up window to test everything)

1. [code]bob = system.gui.getParentWindow(event).getRootContainer()

bob.foo()[/code]

1. 

```auto
event.source.parent.foo()
```

The weird problem that took me half a day to track down 😆

The actual name of the script I was trying to run is:

LSRun

No matter how I tried to call it, I would get the following error message

[code]Root Container  
ERROR [ActionAdapter-AWT-EventQueue-2] Error executing script for event:&nbsp;`mouseReleased`  
on component:&nbsp;`Label`.  
Traceback (most recent call last):  
File “event:mouseReleased”, line 5, in   
TypeError: ‘unicode’ object is not callable

```
at org.python.core.Py.TypeError(Py.java:235)
at org.python.core.PyObject. __call__ (PyObject.java:316)
at org.python.core.PyObject. __call__ (PyObject.java:371)
at org.python.core.PyObject. __call__ (PyObject.java:375)
at org.python.pycode._pyx1149.f$0(<event:mouseReleased>:7)
at org.python.pycode._pyx1149.call_function(<event:mouseReleased>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:623)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:168)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:265)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at com.sun.proxy.$Proxy32.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

```

[/code]

however, if I got rid of just one of the capitol letters i.e. LsRun or LSrun everything works fine or I were to place another letter in front of it (yLSRun) or do just about any other thing it all works. I’m guessing there is some reserved function that starts with LSR (all caps) that it mistakenly thinks I’m calling. That or there’s just some weird bug about a function that starts with LSR (all caps).

---

<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:** [June 21, 2016, 1:24am UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834/6 "2016-06-21T01:24:23Z")

</div>

One of the NetBeans rules for naming properties and methods is that they start with a lower case letter. Class names are expected to start with a capital letter. While jython doesn’t enforce those rules on pure jython, they could certainly impact Java/Jython blends like this.

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 21, 2016, 1:59am UTC](https://forum.inductiveautomation.com/t/accessing-scripting-on-window-or-root-container-from-compent/11834/7 "2016-06-21T01:59:38Z")

</div>

Oh, I assure you, I will be remembering this 😆 Thanks for the help, it got me circling around the ultimate problem (that’ll teach me to be lazy and put foo down for a function I’m having problems with instead of the actual name)
