# Save/restore component properties to DB

**URL:** <https://forum.inductiveautomation.com/t/save-restore-component-properties-to-db/88383>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 4, 2024, 10:07pm UTC](https://forum.inductiveautomation.com/t/save-restore-component-properties-to-db/88383 "2024-04-04T22:07:48Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![David\_Nicks](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@David\_Nicks](https://forum.inductiveautomation.com/u/David_Nicks)\
**Post date:** [April 8, 2024, 8:40pm UTC](https://forum.inductiveautomation.com/t/save-restore-component-properties-to-db/88383/5 "2024-04-08T20:40:59Z")

</div>

Ok, boneheaded mistake on my part, thanks for pointing out the bad syntax on `getattr()`.

Follow-up question since I'm now running into other issues. I am able to use getattr() and save component properties to the DB. However, when I attempt to restore the properties from the DB to the component, I'm getting errors. I'm using the recommendation from @pturmel in [this thread](https://forum.inductiveautomation.com/t/function-to-set-component-property/15074/2) to try both `setattr()` and `setPropertyValue` and it looks like both are failing.

project script:

```auto
def testwriteprops(comp):
	logger = system.util.getLogger("project.functions.testwriteprops")
	logger.trace("test write comp: %s" %(str(comp)))
	prop = 'props.filters.active'
	value = {u'priorities': {u'high': True, u'critical': True, u'low': True, u'diagnostic': False, u'medium': True}, u'text': u'', u'conditions': {u'provider': u'', u'source': u'', u'displayPath': u''}, u'results': {u'data': [], u'enabled': False}, u'states': {u'activeAcked': True, u'clearAcked': False, u'clearUnacked': True, u'activeUnacked': True}}
	try:
		logger.trace("trying setattr")
		setattr(comp,prop,value)
		logger.trace("used setattr")
	except AttributeError:
		logger.trace("trying setPropertyValue")
		comp.setPropertyValue(prop,value)
		logger.trace("used setPropertyValue")
	logger.trace("filters saved")

```

calling script on a button:

```auto
def runAction(self, event):
	comp = self.getSibling("AlarmStatusTable")
	project.functions.testwriteprops(comp)

```

Log output:

> Error running action 'component.onActionPerformed' on testview@D/root/PasteButton: Traceback (most recent call last): File "function:runAction", line 26, in runAction File "module:project.functions", line 738, in testwriteprops AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'setPropertyValue'

Seems like I'm not doing a proper job of retrieving the component reference, but I don't know why. The logger shows the value of `comp` as `com.inductiveautomation.perspective.gateway.script.ComponentModelScriptWrapper$SafetyWrapper@2f507ffb`

---

_[View the full topic](https://forum.inductiveautomation.com/t/save-restore-component-properties-to-db/88383)._
