Timestamp via Call a Script Automation

Hi guys~

I have a Daily Time Record App and here is the scenario:

Under the Table 'LOGSHEET'

We have a single device wherein each logging employee will input his/her:
[Employee ID]
[Employee Image]
[Location]

[DATE] and [TIMESTAMP] are ticked as not Editable of course to avoid changes..

However, it's been discovered recently that some employees manipulate their logs by changing the device's time so their logs show they're on time when they're actually not.

I have read in previous posts/threads that it has not yet been resolved so far...

I was thinking doing another timestamp type that we can call [ACTUAL TIMESTAMP] but its formula will not be under App Formula or Initial Value but rather a Timestamp value that will be derived by using automation (Call a Script) function.

My current Appscript is shown below:

 

function onEdit(e) {
 
var ss = SpreadsheetApp.getActiveSheet();
var r = ss.getActiveCell();
if (r.getColumn() == 1 && r.getRow() > 1 && ss.getName()=='LOGSHEET') {
var celladdress ='p'+ r.getRowIndex()
ss.getRange(celladdress).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm");
}
};
 Where Column 1 = is the [LOG ID] and this is the determining factor of the script if a record has been added; and
Where Column 'p' is the column of [ACTUAL TIMESTAMP]
 
What I want to happen is, every time a row is added, saved and synced on google sheets, a workflow will run by calling a script and it encodes a timestamp on [ACTUAL TIMESTAMP]
 
Please note that [TIMESTAMP] and [ACTUAL TIMESTAMP] are two different columns. [TIMESTAMP] may show the manipulated time by the employee and [ACTUAL TIMESTAMP] will reflect the time via appscript. The difference will then be considered as time tampered and Employee will be subject to an explanation.
 
Screenshot 2023-07-30 at 3.56.48 PM.png
As you guys can see, my current appscript creates an error when I check it on Appsheet Monitoring. Something is just wrong with my function and I hope that you can help me!
 
P.S I got my current appscript from my other google sheet scripts wherein changes are made directly in the sheet.. It works perfectly on Google Sheets.
 
Thank you!
0 4 1,325
4 REPLIES 4
Top Labels in this Space