# Scripting reference parent property with parameter

**URL:** <https://forum.inductiveautomation.com/t/scripting-reference-parent-property-with-parameter/68513>\
**Category:** Ignition\
**Created:** [January 11, 2023, 8:37pm UTC](https://forum.inductiveautomation.com/t/scripting-reference-parent-property-with-parameter/68513 "2023-01-11T20:37:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Shivne](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Aaron\_Shivne](https://forum.inductiveautomation.com/u/Aaron_Shivne)\
**Post date:** [January 11, 2023, 8:37pm UTC](https://forum.inductiveautomation.com/t/scripting-reference-parent-property-with-parameter/68513/1 "2023-01-11T20:37:05Z")

</div>

Attempting to use Project Library script to change a parent component property.  
The property name is supplied to Parameter prop.

The below script does not work I get an error stating the 'Object has not attribute 'Prop''

I have added a switch function using IF and ELIF which works except [props = value] does not set the property.

```auto
def propChange (comp, prop, dataset, event):
	par = event.source.parent
	compo = par.getComponent(comp)
	props = par.prop
	
	
	if props == 0:
		value = 1
	
	elif props == 1:
		value = 0
		
	props = value
	comp.setDatasetEnabled(dataset, value)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 11, 2023, 9:00pm UTC](https://forum.inductiveautomation.com/t/scripting-reference-parent-property-with-parameter/68513/2 "2023-01-11T21:00:17Z")

</div>

If you want to read a property (of a certain name) dynamically, use the Python builtin `getattr`:

```auto
def propChange (comp, prop, dataset, event):
	par = event.source.parent
	compo = par.getComponent(comp)
	props = getattr(par, prop)
	
	if props == 0:
		value = 1
	
	elif props == 1:
		value = 0
		
	props = value
	comp.setDatasetEnabled(dataset, value)

```

Assuming `prop` is passed in as something like `"value"`.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 11, 2023, 9:15pm UTC](https://forum.inductiveautomation.com/t/scripting-reference-parent-property-with-parameter/68513/3 "2023-01-11T21:15:02Z")

</div>

You could get rid of the if/elif statements.

```python
# if you really need an integer value
value = int(not props)

# if a boolean will work
value = not props

```

---

<div class="post-metadata">

**Author:** ![Aaron\_Shivne](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Aaron\_Shivne](https://forum.inductiveautomation.com/u/Aaron_Shivne)\
**Post date:** [January 11, 2023, 9:54pm UTC](https://forum.inductiveautomation.com/t/scripting-reference-parent-property-with-parameter/68513/4 "2023-01-11T21:54:11Z")

</div>

That code corrected the first issue. Now I having the the second issue which is that

props = value

does not set the property. The property is Boolean the parameter prop is passed in as a string.

---

<div class="post-metadata">

**Author:** ![Aaron\_Shivne](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Aaron\_Shivne](https://forum.inductiveautomation.com/u/Aaron_Shivne)\
**Post date:** [January 11, 2023, 9:58pm UTC](https://forum.inductiveautomation.com/t/scripting-reference-parent-property-with-parameter/68513/5 "2023-01-11T21:58:41Z")

</div>

Found the solution. I need to also uses setattr

```auto
def propChange (comp, prop, dataset, event):
	par = event.source.parent
	compo = par.getComponent(comp)
	props = getattr(par, prop)
	
	value = not props
		
	setattr(par, prop, value)
	
	compo.setDatasetEnabled(dataset, value)

```
