Duplication of data

Hi,

I have an issue that I'm struggling to figure out the reason for.
In a factory I have a set of views divided on different areas of the factory floor. So one view will contain a set of light columns machines and another view some other. These views have their own dashboard component with a 'on change script' on the widget property;

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	from com.inductiveautomation.ignition.common import TypeUtilities

	jsonWidgets = TypeUtilities.pyToGson(self.props.widgets)
	serializedWidgets = system.util.jsonEncode(jsonWidgets)
	dashboardID = self.view.params.dashboardID
	productionLineID = self.view.params.productionLineID

	dbCon = system.tag.read("[default]/My Tags/DB_con").value

	dUpdated = system.date.now()
	dateUpdated = system.date.format(dUpdated, "yyyy-MM-dd HH:mm:ss")
	system.db.runPrepUpdate("UPDATE tblAreaOverviewConfiguration_rev2 SET newWidgets = ?,dateUpdatedPROMO = ? WHERE dashboardID = ? AND productionLineID = ?",(serializedWidgets,dateUpdated,dashboardID,productionLineID),dbCon)

For some unknown reason I get the view of one part overwritten to another.
So for example view 'One' contains widgets 'A' & 'B' and another view 'Two' contains 'C' & 'D'. Every now and then 'Two's widgets will be overwritten with 'A' & 'B' instead of 'C' & 'D'. Here is the startup script when you load the view;

def runAction(self):
	dbCon = system.tag.read("[default]/My Tags/DB_con").value
	dashboardID = self.view.params.dashboardID
	productionLineID = self.view.params.productionLineID
	
	serializedWidgets = system.db.runScalarPrepQuery("SELECT newWidgets FROM tblAreaOverviewConfiguration_rev2 WHERE dashboardID =? AND productionLineID =?", [dashboardID,productionLineID],dbCon)		
	self.getChild("dshAreaOverView").props.widgets = system.util.jsonDecode(serializedWidgets)

Can't see where it goes wrong, could you help me out?

Best regards,
Rickard Nordwall

Please post code - not pictures of code - so we can copy and edit it in our answers. See Wiki - how to post code on this forum. Thanks.

1 Like

I think you have a race condition between your view startup script and your parameters' initial values.

You should simply bind a named query to props.widgets that takes your IDs as its parameters. With a simple transform to decode the JSON from the DB.

Use bindings before property change or startup scripts, if at all possible.

2 Likes