Note: This specific code is being executed on ignition perspective platform, but the problem I am having is more related to logic than platform.
Problem Description:
I'm encountering a problem with updating entries in an array named Asset_Insert within an Ignition Perspective project. When I modify a cell value in a table, the Asset_Insert array should be updated with the new data. However, instead of updating the existing entry, a new entry is being added each time. (The method will be executed every time on each commit/value + enter)
def runAction(self, event):
col = event.column
row = event.row
BASE_ASSET_NAME = self.getSibling("Txt_Selected_BT").props.text
plantName = self.props.data[0].Plant_Name.value
assetInsert = self.custom.Asset_Insert
if 'value' in self.props.data[row][col]:
self.props.data[row][col]['value'] = event.value
# Flag to check if we found the row to update
updated = False
# Iterate and update existing entry
for i, item in enumerate(assetInsert):
if item["ASSET_NAME"] == asset_data["ASSET_NAME"]:
# Update existing entry
assetInsert[i] = asset_data
updated = True
break
# Append the asset_data if not updated
if not updated:
assetInsert.append(asset_data)
Request for Help:
How can I modify the code to ensure that the existing entry in Asset_Insert is updated rather than creating a new one?
Any suggestions or insights on how to resolve this issue would be greatly appreciated.
I have used for loop to iterate through the items in Asset_Insert array, but it only works if there is only 1 row in the table if there are more than 1 rows in the table then it will first create the number of objects as per the number of rows then will keep updating the last object.
ASSET_NAME. Then it will go toif not updated:and insert a new row. So the problem is that the asset name doesn't match.asset_data? Maybe you should be usingBASE_ASSET_NAME?assetInsertcan be left out.