# Vision Table onCellEdited system.gui.confirm popup two times

**URL:** <https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [December 31, 2020, 5:19am UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873 "2020-12-31T05:19:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [December 31, 2020, 5:19am UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/1 "2020-12-31T05:19:17Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/5/95f583c1ec5bb700deb7e0c0a7372d2ebb7dfdd1.png)

```auto
	if system.gui.confirm(u'你确定是要将铜片数量修改么？'):
		CorePlate=self.data.getValueAt(rowIndex,'CorePlate')
		query="""
		UPDATE [dbo].[CorePlate]
		   SET [Count] =?
		 WHERE CorePlate=?
		"""
		args=[newValue, CorePlate]
		system.db.runPrepUpdate(query,args,"MaluProduction")

```

Before the people edit the data of a power table, I need popup a confirm window, upside is my current logic, but that will popup two times, how to make this logic popup only 1 time?

---

<div class="post-metadata">

**Author:** ![tarun89engg](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tarun89engg](https://forum.inductiveautomation.com/u/tarun89engg)\
**Post date:** [February 4, 2021, 3:28pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/2 "2021-02-04T15:28:16Z")

</div>

how you have resolved this problem?  
I would also like to do the same.

can you please share some code.  
Thanks

---

<div class="post-metadata">

**Author:** ![Rusty](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rusty/32/19859_2.png) [@Rusty](https://forum.inductiveautomation.com/u/Rusty)\
**Post date:** [March 23, 2021, 2:19pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/3 "2021-03-23T14:19:34Z")

</div>

This confirmation is also popping up twice for me, any solution yet?

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [March 23, 2021, 5:26pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/4 "2021-03-23T17:26:40Z")

</div>

This has to do with how focus can mess with the commit system that the onCellEdited event uses. There is a workaround though. If you move the code out of onCellEdited and into a custom method, you can call it using system.util.invokeLater().  
Here’s an example where self.showPopup just contains the same code that used to be in onCellEdited():

 ![popup](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/b/dbda49e0ce06bc4d89178a165aa9acd4178fef64.png)

---

<div class="post-metadata">

**Author:** ![Rusty](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rusty/32/19859_2.png) [@Rusty](https://forum.inductiveautomation.com/u/Rusty)\
**Post date:** [March 23, 2021, 6:16pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/5 "2021-03-23T18:16:55Z")

</div>

Thanks for your help. I just tried your tip, but the window is still popping up twice and I’m getting an error with it, perhaps I’m doing it wrong, I’ve never experimented with custom functions. Here is what I have in “onCellEdited”:

```auto
def onCellEdited(self, rowIndex, colIndex, colName, oldValue, newValue):
	"""
	Called when the user has edited a cell in the table. It is up to the
	implementation of this function to alter the underlying data that drives
	the table. This might mean altering the dataset directly, or running a SQL
	UPDATE query to update data in a database.

	Arguments:
		self: A reference to the component that is invoking this function.
		rowIndex: Index of the row that was edited, relative to the underlying
		          dataset
		colIndex: Index of the column that was edited, relative to the
		          underlying dataset
		colName: Name of the column in the underlying dataset
		oldValue: The old value at the location, before it was edited
		newValue: The new value input by the user.
	"""
	system.util.invokeLater(self.showPopup(rowIndex, colIndex, colName, oldValue, newValue)) #I'm assuming this is how I pass these values into the custom function, but please correct me if it's wrong
	

```

Here is what I have in the custom method,(parameters are: colIndex, colName, oldValue, newValue):

```auto
def showPopup(self, rowIndex, colIndex, colName, oldValue, newValue):	
	"""
	Arguments:
		self: a reference to the component instance this method is invoked on.
	"""
	customer = self.data.getValueAt(rowIndex, 'Customer')
	product = self.data.getValueAt(rowIndex, 'ProductName')
	
	newText = str(newValue)
	
	if system.gui.confirm(u'Really submit entry "' + newText + '" as ' + colName + ', for customer: ' + customer + ', product: ' + product +'? You cannot undo this action!'):
		# Get the id of the row we edited.
		id = self.data.getValueAt(rowIndex, 'Spec_Index')
	 	
		# Create our query and arguments. The extension function gives us a colName variable,
		# which we can use in our query. The query will then take two arguments.
		# The value that we are updating and the id of the row we edited.
		query = "UPDATE Product_Specs SET %s = ? WHERE Spec_Index = ?" % (colName)
		args = [newValue, id]
		 
		# Run the query with the specified arguments.
		
		system.db.runPrepUpdate(query, args)
		
		# Requery the database, so we can ensure it properly updated the table.
		system.db.refresh(self, "data")

```

The error is the following:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/8/a87dcfa302a69b8d6a7142893a98a9eeadb7d834.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/4/a460e6ad41095cb163720b66f1bec1d6692e35c1.png)

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [March 23, 2021, 6:37pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/6 "2021-03-23T18:37:36Z")

</div>

Oh right if you need to pass in arguments you are better off using `system.util.invokeAsynchronous()` I should have suggested that from the start. That function takes in the function as the first argument, then a list of values or dictionary of arguments. Using what you want to pass in, it should look more like:

```auto
system.util.invokeAsynchronous(self.showPopup,[rowIndex, colIndex, colName, oldValue, newValue])

```

Edit:  
pturmel is right, this should be called using system.util.invokeLater() **not** invokeAsynchronous. However this comes with the issue that it cannot have passed in parameters. The script itself would likely have to need some refactoring to have the function itself gather the right info itself or placed directly in the script here so that it has access to the function’s variables.

---

<div class="post-metadata">

**Author:** ![Rusty](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rusty/32/19859_2.png) [@Rusty](https://forum.inductiveautomation.com/u/Rusty)\
**Post date:** [March 23, 2021, 6:40pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/7 "2021-03-23T18:40:28Z")

</div>

> [@osolorzano](#):
>
> system.util.invokeAsynchronous(self.showPopup,[rowIndex, colIndex, colName, oldValue, newValue])

Perfect, this solved it for me, Thanks @osolorzano!

---

<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:** [March 23, 2021, 10:14pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/8 "2021-03-23T22:14:06Z")

</div>

Ewww! That’s not safe to call from a background thread!

---

<div class="post-metadata">

**Author:** ![martinel37461](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@martinel37461](https://forum.inductiveautomation.com/u/martinel37461)\
**Post date:** [April 18, 2021, 3:27am UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/9 "2021-04-18T03:27:50Z")

</div>

I’m having the same problem but don’t need to pass parameters anywhere -  
Version 7.9.17; Vision Power Table; Extension Functions; onCellEdited  
I just want a confirmation from the user.

```auto
response = system.gui.confirm( '<html>SKU <b>%s</b> is not in the database.<br><b>Add %s to the Database?' %(sku,sku), 'Add SKU %s to the Database?' %sku, False )

```

The code works fine on the first run; after asking the user for a second confirmation, I get database duplicate record error on the second run (easy to try/except out of that).  
I added:

```auto
if newValue == oldValue:
	return

```

but it still runs twice.  
I’ll try @osolorzano suggestion to invokeLater, just seems unnecessary.

---

<div class="post-metadata">

**Author:** ![martinel37461](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@martinel37461](https://forum.inductiveautomation.com/u/martinel37461)\
**Post date:** [April 18, 2021, 3:35am UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/10 "2021-04-18T03:35:58Z")

</div>

system.util.invokeLater fixes it for me.

---

<div class="post-metadata">

**Author:** ![cdunn.home](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@cdunn.home](https://forum.inductiveautomation.com/u/cdunn.home)\
**Post date:** [September 8, 2022, 2:13pm UTC](https://forum.inductiveautomation.com/t/vision-table-oncelledited-system-gui-confirm-popup-two-times/41873/11 "2022-09-08T14:13:19Z")

</div>

I solved this by adding a Boolean custom property to my PowerTable. I named it "isEditing".

I start onCellEdited with

> if self.isEditing:  
> return  
> self.isEditing = True

Then at every other point I end the function:

> self.isEditing = False
