# Getcomponent() problem

**URL:** <https://forum.inductiveautomation.com/t/getcomponent-problem/9280>\
**Category:** Ignition\
**Created:** [November 3, 2014, 10:38pm UTC](https://forum.inductiveautomation.com/t/getcomponent-problem/9280 "2014-11-03T22:38:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwj](https://avatars.discourse-cdn.com/v4/letter/k/838e76/32.png) [@kwj](https://forum.inductiveautomation.com/u/kwj)\
**Post date:** [November 3, 2014, 10:38pm UTC](https://forum.inductiveautomation.com/t/getcomponent-problem/9280/1 "2014-11-03T22:38:12Z")

</div>

I have the following script:

`def updateInputs(window):
	for comp in window.getRootContainer().getComponents():
		if comp.name.startswith('Input') :
			comp.getComponent('textfield').floatValue = comp.In_Value`

On the window in question, I have a number of instances of a template that contain a numeric text field (“textfield”). I am using it to change a tag through some scripting (its not just bound to a tag). So when the window opens, the values are all 0. I want them to open at the value of the tag (hence the script, which is called when the window opens).

When the script is called, I get TypeError: getComponent(): 1st arg can’t be coerced to int. I have also tried .intValue instead of .floatValue with the same result. In\_Value is a custom property (float) of the template containing “textfield”.

Any ideas?

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [November 3, 2014, 11:33pm UTC](https://forum.inductiveautomation.com/t/getcomponent-problem/9280/2 "2014-11-03T23:33:32Z")

</div>

[quote=“kwj”]I have the following script:

`def updateInputs(window):
	for comp in window.getRootContainer().getComponents():
		if comp.name.startswith('Input') :
			comp.getComponent('textfield').floatValue = comp.In_Value`

On the window in question, I have a number of instances of a template that contain a numeric text field (“textfield”). I am using it to change a tag through some scripting (its not just bound to a tag). So when the window opens, the values are all 0. I want them to open at the value of the tag (hence the script, which is called when the window opens).

When the script is called, I get TypeError: getComponent(): 1st arg can’t be coerced to int. I have also tried .intValue instead of .floatValue with the same result. In\_Value is a custom property (float) of the template containing “textfield”.

Any ideas?[/quote]

You already have a reference to the component, all you have to do is:

[comp]comp.floatValue = comp.In\_Value[/code]

Edit: Nevermind, on a 2nd read I see that you are looking for a child component of the template. You might have to use comp.getParent().getComponent(“textfield”) but I can’t test it right now.

---

<div class="post-metadata">

**Author:** ![kwj](https://avatars.discourse-cdn.com/v4/letter/k/838e76/32.png) [@kwj](https://forum.inductiveautomation.com/u/kwj)\
**Post date:** [November 4, 2014, 10:25pm UTC](https://forum.inductiveautomation.com/t/getcomponent-problem/9280/3 "2014-11-04T22:25:48Z")

</div>

“NoneType object has no attribute floatValue”

Crap. Thanks for the suggestion though.

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [November 4, 2014, 11:02pm UTC](https://forum.inductiveautomation.com/t/getcomponent-problem/9280/4 "2014-11-04T23:02:10Z")

</div>

Is comp.In\_Value bound to the tag value? If so I would think that you could update the value of the numeric text field from within the template when the value of In\_Value changes.
