# Firing an event for window onOpen

**URL:** <https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107>\
**Category:** Archived Topics\
**Created:** [September 21, 2006, 8:23pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107 "2006-09-21T20:23:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [September 21, 2006, 8:23pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/1 "2006-09-21T20:23:09Z")

</div>

I have a window with a few dozen tanks, with various labels and such. The tank and its level indicators, temperature labels, etc. are grouped into a container (cntTank\_1, for example) and I think copied it many times, renaming it cntTank\_2, etc.

When this window opens, I am passing it a parameter that identifies the cellar number. Based on that I would like to make visible only the number of tanks in that cellar. Is the internalFrameOpened action for the window the correct way to do this? I suppose it would be a switch statement making cntTank\_1.visible=0 or 1?

Related to this, I have a dataset that is populated based on that same cellarnum parameter I pass in. It will have as many rows as there are tanks, and has a dozen columns or so. Is the best approach to populating labels and such to iterate through that dataset at the same time I make visible or invisible the tank containers. I guess I would go row by row, column by column to assign data to objects? Any advice would be appreciated. TIA D. Lewis

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [September 21, 2006, 9:37pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/2 "2006-09-21T21:37:53Z")

</div>

To answer the first question, the internalFrameActivated would be the best choice to put this logic. Then you would, as you said, set the visible property to 0 or 1 based on your logic. It would be something like:`event.source.rootContainer.getComponent("cntTank_1").visible=1`

However, why do this in scripting at all? I would simply bind the visible property of the container do an expression involving the cellar number. This would be easier and more maintainable.

For the second question: Yes, you could iterate through the dataset and assign values to properties. (see the fpmi.db.toPyDataSet() function).

Again, though, I would simply bind your properties (label texts, tank levels, etc) to an expression involving the cellar data, and tank number. For example, suppose that we are binding for tank 6, and only cellar numbers less than #4 had 6 or more tanks. The expression for a label text would look something like this:

`if ({rc.cellarNum} < 4,
  {rc.cellarData}[6, "SomeColumn"], // bind into the dataset at row 6
  '') // blank text, cellers >= 4 don't have 6 tanks`

Let me know if you need some more explaination about this,

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [September 21, 2006, 9:46pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/3 "2006-09-21T21:46:13Z")

</div>

Much easier as you propose it. Thx. D

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [September 21, 2006, 9:50pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/4 "2006-09-21T21:50:57Z")

</div>

No problem. FYI: for binding numbers using this technique, the expression would look like this:

`if ({rc.cellarNum} < 4, 
  toInt({rc.cellarData}[6, "SomeColumn"]), // bind into the dataset at row 6 
  -1) // use -1 for 'invalid', cellers >= 4 don't have 6 tanks`

Glad to have helped,

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [September 29, 2006, 4:21pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/5 "2006-09-29T16:21:37Z")

</div>

Hi All:

On the internalFrameActivated event of my startup window, I placed the following code:

```auto
lbln_Avg_OG = event.source.parent.getComponent("lbln_Avg_OG") 
lbln_Avg_OG.text = 0

```

The label in question is a numeric lable. I also tried

lbln\_Avg\_OG.text=“0” but got the same error (see below).

How should I go about clearing out the textboxes? TIA D. Lewis

Traceback (innermost last):  
File “event:internalFrameActivated”, line 1, in ?  
TypeError: getComponent(): 1st arg can’t be coerced to int

```
at org.python.core.Py.TypeError(Py.java)
at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java)
at org.python.core.PyMethod. __call__ (PyMethod.java)
at org.python.core.PyObject. __call__ (PyObject.java)
at org.python.core.PyInstance.invoke(PyInstance.java)
at org.python.pycode._pyx0.f$0(<event:internalFrameActivated>:1)
at org.python.pycode._pyx0.call_function(<event:internalFrameActivated>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.calmetrics.factoryhmi.application.script.ScriptManager.runCode(ScriptManager.java:156)
at com.calmetrics.factoryhmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:137)
at com.calmetrics.factoryhmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:277)
at com.calmetrics.factoryhmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:54)
at $Proxy1.internalFrameActivated(Unknown Source)
at javax.swing.JInternalFrame.fireInternalFrameEvent(Unknown Source)
at javax.swing.JInternalFrame.setSelected(Unknown Source)
at javax.swing.JInternalFrame.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at javax.swing.JComponent.setVisible(Unknown Source)
at com.calmetrics.factoryhmi.application.FHMIApp.openWindow(FHMIApp.java:477)
at com.calmetrics.factoryhmi.application.FHMIApp.openWindow(FHMIApp.java:426)
at com.calmetrics.factoryhmi.application.FHMIApp.startup(FHMIApp.java:386)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel.initFHMIApp(RuntimePanel.java:750)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction.doLogin(RuntimePanel.java:1106)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction.tryLoadApp(RuntimePanel.java:1140)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction.access$600(RuntimePanel.java:1011)
at com.calmetrics.factoryhmi.application.runtime.RuntimePanel$LoginAction$LoginLockWaiter$1.run(RuntimePanel.java:1043)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
```

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [September 29, 2006, 5:54pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/6 "2006-09-29T17:54:26Z")

</div>

David,

The problem is actually in the first line of this script. Since this event is an event of the window, event.source refers to the window itself. Thus, getting the parent of the window isn’t what you want to do. Rather, you want to get the root container of the window.

Also, you do need to make sure that you are assigning strings to text properties of labels. I think that the script as written below will work:

`lbln_Avg_OG = event.source.rootContainer.getComponent("lbln_Avg_OG") 
lbln_Avg_OG.text = "0"`

Another note - if your goal is to simply ‘zero out’ this text when the window starts, you can do something like bind the text to the expression `"0"` or the SQL query `SELECT '0'` with polling off. Either way (scripting vs binding) will work fine though.

Hope this helps,

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [September 29, 2006, 5:58pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/7 "2006-09-29T17:58:20Z")

</div>

Hi Carl: Thanks. I suspected it was something in the way I was addressing the control. I sent a note off list to Nathan about this very subject. I like the alternative approach as well. D

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [September 29, 2006, 6:01pm UTC](https://forum.inductiveautomation.com/t/firing-an-event-for-window-onopen/107/8 "2006-09-29T18:01:06Z")

</div>

David. I didn't get the note. Was it an email or private message?

edit - correction, got the email

> [@David](#):
>
> Hi Carl: Thanks. I suspected it was something in the way I was addressing the control. I sent a note off list to Nathan about this very subject. I like the alternative approach as well. D
