# How to Enter Time stamp when Power Table Cell is Updated

**URL:** <https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [July 31, 2019, 1:10am UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029 "2019-07-31T01:10:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulm1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paulm1/32/5900_2.png) [@paulm1](https://forum.inductiveautomation.com/u/paulm1)\
**Post date:** [July 31, 2019, 1:10am UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/1 "2019-07-31T01:10:57Z")

</div>

I am using the following script to Update changes made to a Power Table.

```
row = rowIndex
col = colIndex
colName = colName
value = newValue
		
ndx = self.data.getValueAt(row,0)
query = "UPDATE brewdaily SET %s = ? WHERE ndx = ?" % colName
system.db.runPrepUpdate(query,[value,ndx],'history')
system.db.refresh(self.data)

```

This table (brewdaily) is for operators to check off their daily tasks.  
When they are viewing this PowerTable they see -

 ![BrewDaily1](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/18f6bb5db4fbdc39f6c9e2634d3c2790016f34d8.png)

How can I enter a timestamp into column “Time Stamp” when the operator checks one of the corresponding cells in the Column labeled “Complete”?

---

<div class="post-metadata">

**Author:** ![paulm1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paulm1/32/5900_2.png) [@paulm1](https://forum.inductiveautomation.com/u/paulm1)\
**Post date:** [July 31, 2019, 3:17pm UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/2 "2019-07-31T15:17:55Z")

</div>

I am not sure how efficient this is, but the following script appears to be doing what I intended.  
I would still appreciate ant help this forum can offer in improving it.

 ![BrewDaily2](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/bbf8e93cd7731c5d7aa09f8456974f459595d8e1.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 31, 2019, 3:21pm UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/3 "2019-07-31T15:21:09Z")

</div>

Your code looks fine - you should probably check whether the edited cell is in the appropriate column (unless you’re already doing that, higher up in the script). Also, you can combine your UPDATE statements into one call - just combine the two columns:

```python
query = """
UPDATE
    brewdaily
SET
    %s = ?
    t_stamp = ?
WHERE
    ndx = ?
""" % colName
system.db.runPrepUpdate(query, [value, EntryTime, ndx], 'history')

```

(Also - indenting the SQL like that is totally optional; but in my opinion, makes it a lot more readable over time).

---

<div class="post-metadata">

**Author:** ![paulm1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paulm1/32/5900_2.png) [@paulm1](https://forum.inductiveautomation.com/u/paulm1)\
**Post date:** [July 31, 2019, 3:23pm UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/4 "2019-07-31T15:23:59Z")

</div>

How would I check for the appropriate column being checked?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 31, 2019, 3:26pm UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/5 "2019-07-31T15:26:56Z")

</div>

`onCellEdited` passes a `colName` parameter to you, which you could check to make sure the column that was edited is one of the columns you expect - although, actually, what I thought might happen (circular referencing, where editing ‘complete’ edits ‘t\_stamp’ and fires the script again) won’t actually happen due to the way `onCellEdited` works.

---

<div class="post-metadata">

**Author:** ![paulm1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paulm1/32/5900_2.png) [@paulm1](https://forum.inductiveautomation.com/u/paulm1)\
**Post date:** [July 31, 2019, 3:37pm UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/6 "2019-07-31T15:37:14Z")

</div>

First I simplified my query as you suggested. Still works great. But enters the Time when any cell is edited. Then I made some (rookie) attempts at targeting the column “Complete”. So far no luck.  
if colName == ‘complete’:

…and then it goes bad.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 31, 2019, 5:06pm UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/7 "2019-07-31T17:06:34Z")

</div>

Looks like you have capitalized complete so maybe:

```auto
if colName == 'Complete':
    #your script here

```

You might also consider using the table customizer to make only the complete column editable by the user.

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [July 31, 2019, 5:31pm UTC](https://forum.inductiveautomation.com/t/how-to-enter-time-stamp-when-power-table-cell-is-updated/27029/8 "2019-07-31T17:31:55Z")

</div>

May want to set the timestamp from the query. Not sure if system.date. now uses the gateway or client time.
