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 to try both setattr()
and setPropertyValue
and it looks like both are failing.
project script:
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:
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