if event.propertyName == 'componentRunning' and event.newValue and event.source.columnName != '':
initialValue = int(system.db.runScalarQuery("SELECT %s FROM listusers WHERE idx = %i"%(event.source.columnName, system.tag.read('[client]userId').value)))
print "initializing dd_Dates to %i"%(initialValue)
event.source.dd_dates = initialValue
to initialize a template values.
Later, I also want to update, but I want to add the componentRunning as part of the conditional like this
if event.propertyName == 'dd_dates' and event.source.componentRunning:
event.source.finalDateType = event.newValue
if event.source.columnName != '':
qry = "UPDATE listusers SET %s = %i WHERE idx = %i"%(event.source.columnName, event.newValue, system.tag.read('[client]userId').value)
print "update date selection qry: " + str(qry)
system.db.runUpdateQuery(qry)
However, I am getting an error
Traceback (most recent call last):
File "<event:propertyChange>", line 15, in <module>
AttributeError: 'com.inductiveautomation.factorypmi.application.com' object has no attribute 'componentRunning'
Why is it I can catch the propretyChange event for componentRunning but can’t access it after that? Is there a way to access it?
A PropertyChange event can be generated programmatically, with no actual property to back it up, just some state machine. I would not trust COMPONENT_RUNNING, if I were you.
Yea just realized that. COMPONENT_RUNNING was not helpful. I just made a new internal boolean property that I turn on/off to track this.
However, are you also saying I can’t trust componentRunning in general? I do see that sometimes my other custom properties get triggered before it, so I’m not exactly sure what it’s signifying.
COMPONENT_RUNNING events are fired for all classes that implement the ComponentLifecycle interface. With some edge cases, they’ll be fired whenever the component is added to its container by the layout manager. I don’t think any guarantees are made about order of operations/evaluations with regard to bindings.
Just from what I observe in the print statements, it seems like a template instance runs through all custom properties/template properties once for some initial value action I would think, then triggers componentRunning, and then each property gets hit agian.