r/GoogleAppsScript • u/Individual_Push_5103 • May 21 '26
Question Very New, Very Lost
Hello all. I am trying to create a table where the time and date update automatically when certain fields are filled out. I have no idea what I am not understanding in this process. I got as far as:
the =onEdit(e) simple trigger
the =NOW() to enter the time into a given cell
I am struggling with combining these two together. I tried to enter it as one function into the correct box, but couldn't figure out the formatting.
I attempted to look at a 'creating' (copy/pasting) into the script editor, but I don't understand the language very well yet, so when I try to customize or apply it I can't tell if it's even working.
Any help would be appreciated. Thank you in advance.
6
u/krakow81 May 21 '26
This tutorial goes from pretty much zero, so might help you get started: https://www.benlcollins.com/apps-script/google-apps-script-beginner-guide/
I think Ben Collins is very a clear and accessible writer on many things Google (particularly Sheets, but also Apps Script etc).
3
u/FabriceFx May 23 '26
Hello,
The reason they are hard to combine is that they work differently:
=NOW()is a formula that calculates inside the spreadsheet (and updates constantly), whileonEdit(e)is JavaScript code that runs behind the scenes only when you physically change a cell.To make this work, we don't put
=NOW()in the cell or the script. Instead, we let the script detect the change, calculate the current time using JavaScript, and stamp it directly into the target cell as a permanent value.Here is the exact code you need and a breakdown of how to customize it.
Replace everything in your Script Editor (
Extensions > Apps Script) with this code:JavaScript
To make this work for your specific table, you only need to look at the three lines inside the
CONFIGURATIONsection:targetSheetName: Change"Sheet1"to the exact name of the tab at the bottom of your spreadsheet. Keep the quotation marks around it.watchColumn: This is the column that triggers the action. If you want the timestamp to appear when someone types in Column C, change this number to3.stampColumn: This is where you want the date and time to land. If you want it to appear in Column D, change this number to4.Because this is a simple
onEdit(e)trigger, you cannot test it by clicking the "Run" button inside the Apps Script editor. Doing that will result in an error likeCannot read properties of undefined (reading 'range').Instead:
Ctrl+S/Cmd+S).1
u/Majestic-Director203 May 22 '26
Are you doing like a form or task, what fields are you working with. I feel like datetime / now should work
1
u/AlgoTradingQuant May 21 '26
Gemini or ChatGPT are very good at this