# Duplication of data

**URL:** <https://forum.inductiveautomation.com/t/duplication-of-data/91953>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting, database\
**Created:** [June 17, 2024, 2:03pm UTC](https://forum.inductiveautomation.com/t/duplication-of-data/91953 "2024-06-17T14:03:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rickard\_Nordwall](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@Rickard\_Nordwall](https://forum.inductiveautomation.com/u/Rickard_Nordwall)\
**Post date:** [June 17, 2024, 2:03pm UTC](https://forum.inductiveautomation.com/t/duplication-of-data/91953/1 "2024-06-17T14:03:52Z")

</div>

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;

```python
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;

```python
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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 17, 2024, 2:06pm UTC](https://forum.inductiveautomation.com/t/duplication-of-data/91953/2 "2024-06-17T14:06:11Z")

</div>

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](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). Thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 17, 2024, 2:15pm UTC](https://forum.inductiveautomation.com/t/duplication-of-data/91953/3 "2024-06-17T14:15:16Z")

</div>

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.
