# How to use a Script for the onCellEdited Extension Function?

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631>\
**Category:** Ignition\
**Created:** [June 14, 2020, 1:48pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631 "2020-06-14T13:48:12Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [June 14, 2020, 1:48pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/1 "2020-06-14T13:48:12Z")

</div>

what script is needed to save changes to a power tables dataset? I used the default but it doesn’t seem to work.

```auto
import system
self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 14, 2020, 10:26pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/2 "2020-06-14T22:26:08Z")

</div>

Did you remember to make the column editable in the Table Customizer?

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [June 14, 2020, 10:50pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/3 "2020-06-14T22:50:53Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 15, 2020, 1:32pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/4 "2020-06-15T13:32:41Z")

</div>

Where is it getting its underlying data? Like a query or some other operation?

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [June 18, 2020, 1:34pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/5 "2020-06-18T13:34:53Z")

</div>

no I just typed it in the dataset

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 18, 2020, 1:41pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/6 "2020-06-18T13:41:34Z")

</div>

I see your second line is indented in your post - is it like that in the script? That would be a syntax error.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [June 18, 2020, 3:39pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/7 "2020-06-18T15:39:15Z")

</div>

in my script it is right. But it still doesn’t save the data

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 18, 2020, 4:14pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/8 "2020-06-18T16:14:17Z")

</div>

Not sure where to go from here. Can you upload an export of the window you’re using?

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [June 18, 2020, 4:19pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/9 "2020-06-18T16:19:24Z")

</div>

it stores but if I save it in the designer it overwrites it

---

<div class="post-metadata">

**Author:** ![OscarLucas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscarlucas/32/6417_2.png) [@OscarLucas](https://forum.inductiveautomation.com/u/OscarLucas)\
**Post date:** [January 25, 2021, 12:19pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/10 "2021-01-25T12:19:47Z")

</div>

Same problem, i dont know what to do to allow the user to edit the table.[Taller\_electrico\_2021-01-25\_1319.zip](https://forum.inductiveautomation.com/uploads/short-url/gPxc8LnXQomyehAmqMzwwl9w3W7.zip) (23.1 KB)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 25, 2021, 1:28pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/11 "2021-01-25T13:28:37Z")

</div>

For these tables - do you have a data query going and does that have polling? If so, any edits you do will be lost the next time the data gets polled.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 25, 2021, 1:38pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/12 "2021-01-25T13:38:06Z")

</div>

@bkarabinchak.psi, yes, there is a polling query.

@OscarLucas, you will need to update the database table if you want the change to be permanent.

---

<div class="post-metadata">

**Author:** ![OscarLucas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscarlucas/32/6417_2.png) [@OscarLucas](https://forum.inductiveautomation.com/u/OscarLucas)\
**Post date:** [January 26, 2021, 7:14am UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/13 "2021-01-26T07:14:44Z")

</div>

How? i don´t know how to save data in de BDD

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/8/f80627f9d3fa90e0d28ad0fd7f1b7d367d3c65fe.png)

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [January 26, 2021, 9:20am UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/15 "2021-01-26T09:20:51Z")

</div>

If you have a query polling the database, you dont need to update the dataset, just write to the database and let the query update the table.

You need to add the database name in the update query if not using the default database.  
system.db.runPrepUpdate(query, args, “database name”)

Also, you don’t need to import system. that happens automatically.

something like this:

```auto
id = self.data.getValueAt(rowIndex, 'id')
query = "Update stock SET %s = ? WHERE id = ?" % (colName)
system.db.runPrepUpdate(query, [newValue, id], "MyDatabase")
system.db.refresh(self, "data")

```

---

<div class="post-metadata">

**Author:** ![OscarLucas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscarlucas/32/6417_2.png) [@OscarLucas](https://forum.inductiveautomation.com/u/OscarLucas)\
**Post date:** [January 26, 2021, 11:15am UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/16 "2021-01-26T11:15:30Z")

</div>

still not updating the data in the database… Thanks for your comments

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/af301ba35758144181a1c5492306228ca1a09cbf.png)

---

<div class="post-metadata">

**Author:** ![schenk](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schenk](https://forum.inductiveautomation.com/u/schenk)\
**Post date:** [January 26, 2021, 11:43am UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/17 "2021-01-26T11:43:07Z")

</div>

Check the console, you’re probably getting an error like `Column 'id' doesn't exist` because your id column is “idreferencia”, not “id”.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 26, 2021, 1:31pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/19 "2021-01-26T13:31:03Z")

</div>

Your column names do not match within your script.

```python
id = self.data.getValueAt(rowIndex, 'idreferencia')
query = 'UPDATE stock SET %s = ? WHERE idreferencia = ?' % (colName)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/818bb61e340bc996f0d73583478cb6d567d4879b.png)

---

<div class="post-metadata">

**Author:** ![OscarLucas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscarlucas/32/6417_2.png) [@OscarLucas](https://forum.inductiveautomation.com/u/OscarLucas)\
**Post date:** [January 27, 2021, 6:30am UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/20 "2021-01-27T06:30:24Z")

</div>

First of all thank you for the help. I’ve tried again and it still doesn’t work. I have checked project properties, I have tried to change the units from the SQL browser successfully and I cannot find the problem in the script.  
Does anyone have any idea what might happen?  
Anyone have an example that works?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8ef514198dbe8d4aa033bbf4eab01d14c9102445.png)

---

<div class="post-metadata">

**Author:** ![OscarLucas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscarlucas/32/6417_2.png) [@OscarLucas](https://forum.inductiveautomation.com/u/OscarLucas)\
**Post date:** [January 27, 2021, 7:26am UTC](https://forum.inductiveautomation.com/t/how-to-use-a-script-for-the-oncelledited-extension-function/35631/21 "2021-01-27T07:26:11Z")

</div>

Finally I got it, I leave the example for the whole community.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/f/7fb6aaab54b83fc615b51ea2b17fe06ffe5890ff.png)
