ahawes
January 23, 2025, 3:40pm
1
Good morning team!!
I am back again with another problem i need help sovling.
I have a table called drop_locations.
area
int
NO
PRI
pos_a
int
NO
PRI
command
varchar(100)
YES
drop_location
varchar(6)
NO
PRI
Active
tinyint(1)
YES
content1
varchar(100)
YES
content2
varchar(100)
YES
In this table, i want to allow a user to udpate the Active column, the content1 and content2 column.
I could do this with an update query and parameters but was wondering if there was a better way.
I have used this in the past to update an boolean item but never have i used it in a table like this.
def runAction(self, event):
self.props.selection.data[0].Active = not self.props.selection.data[0].Active
An update query is your only option here since the data source is a query.
ahawes
January 23, 2025, 3:46pm
3
Great, thanks for teh confirmation.
1 Like
If your data source's polling is turned off, make sure you refreshBinding() so the data is updated on the front end. I still do this if polling is every 30 seconds or more, so the user does not think the edit was not committed.
Should be similar to this.
self.refreshBinding('props.data')
1 Like
ahawes
January 23, 2025, 6:44pm
5
Good afternoon Team,
I have updated and created a new query to manage the change.
When using the script below, it does not update active column.
# update here
active = self.props.selection.data[0].Active
content1 = self.props.selection.data[0]['Pallet Location 1']
content2 = self.props.selection.data[0]['Pallet Location 2']
drop_location = self.props.selection.data[0]['Drop Location']
category = "HMI"
source = "ASCADA Client"
usr = self.session.props.auth.user.id
message = str(usr) + " Updated Drop Table to " + str(active) + " Location " + str(drop_location)
data9 = usr
# Update drop
system.db.runNamedQuery("Tables/ASRS Drop Locations Update",{
"active1": active,
"contentOne" : content1,
"contentTwo" : content2,
"dropLocation" : drop_location,
})
#Update Syslog
system.db.runNamedQuery("Tables/syslog_update",{
"category": category,
"source": source,
"message": message,
"data9": data9
})
UPDATE QUERY
UPDATE `Clemens`.`drop_locations`
SET `Active` = :active1,
'content1' = :contentOne
'content2' = :contentTwo
WHERE (`drop_location` = :dropLocation )
Is your query binding on the table polling or is it turned off?
ahawes
January 23, 2025, 7:04pm
7
It was off, i changed it to polling, 5 secs. Still not working.
Check the gateway logs for scripting errors.
ahawes
January 23, 2025, 7:14pm
9
I see nothing in the gateway logs.
Have you tested the queries to make sure they work?
Are you sure that you have committed the change?
Wouldn't you need to update the data with the onEditCellCommit script? Something like,
self.props.data[event.row][event.column] = event.value
That would update the cell, and that, in turn, would update the selection data which the first line of your script is referencing.
The script could be written as,
self.props.data[event.row][event.column] = event.value
# Update drop
system.db.runNamedQuery("Tables/ASRS Drop Locations Update",{
"active1": self.props.selection.data[0].Active,
"contentOne": self.props.selection.data[0]['Pallet Location 1'],
"contentTwo": self.props.selection.data[0]['Pallet Location 2'],
"dropLocation": self.props.selection.data[0]['Drop Location']
})
#Update Syslog
system.db.runNamedQuery("Tables/syslog_update",{
"category": "HMI",
"source": "ASCADA Client",
"message": str(usr) + " Updated Drop Table to " + str(active) + " Location " + str(drop_location),
"data9": usr
})
1 Like