# Access Windows component from a Project Script on Window Open

**URL:** <https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506>\
**Category:** Ignition\
**Created:** [December 6, 2019, 8:54pm UTC](https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506 "2019-12-06T20:54:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [December 6, 2019, 8:54pm UTC](https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506/1 "2019-12-06T20:54:03Z")

</div>

I would like to access some components in a screen when the screen opens, but from a Project Script so  
it can be used by multiple screens. The screens will have some similar components (i.e. droplist.selectedValue)

I currently call the project script on a button press, now I want to call the same script on screen open.  
I pass the EVENT to the project script  
project.scripts.functionname(event)

Withing the project script I an access any components on the screen using  
event.source.parent.getComponent(‘compname’).property  
since I passed the “event”.

Now I need to call the same script on screen open and I get the error it can’t coerce the “event” parameter into a integer…  
I do not know what to pass from the open event…

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [December 8, 2019, 3:30am UTC](https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506/2 "2019-12-08T03:30:03Z")

</div>

This should work. I use it in many places. Please post your code so we can work out what’s going on.

---

<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:** [December 8, 2019, 12:39pm UTC](https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506/3 "2019-12-08T12:39:37Z")

</div>

Can you be more specific when you say “screen open” event? (there are a few)

---

<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:** [December 8, 2019, 2:20pm UTC](https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506/4 "2019-12-08T14:20:39Z")

</div>

The `event` object content varies by event type. The biggest difference in your case is that events on the Vision window deliver the window itself as `event.source`, while all of the component and container events have that component as `event.source`. Getting to the root container differs based on source. For a window it is `root = event.source.rootContainer`. For a root container event (propertyChange, perhaps), it is just `root = event.source`. For components, you need one or more `.parent` references.

Consider resolving the root container in the calling event, passing it as an additional argument to your project function.

---

<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:** [December 8, 2019, 9:01pm UTC](https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506/5 "2019-12-08T21:01:22Z")

</div>

This is where I will (mostly) always use the `system.gui.getParentWindow(event).rootContainer` function to get the rootContainer regardless of the object. Then you can use the same code everywhere and not worry about if it’ll work or not

---

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [December 9, 2019, 2:20pm UTC](https://forum.inductiveautomation.com/t/access-windows-component-from-a-project-script-on-window-open/30506/6 "2019-12-09T14:20:06Z")

</div>

Thanks guys!! Got it working with your suggestions. I’m fairly new to Ignition scripting and wasn’t familiar to the hierarchy scripting. I changed to passing the root container to the VisionWindowOpened event and then drilling down to the component.
