Google Sheets Script editor... I'm getting error code and need HELP PLEASE!!!!!

82 views
Skip to first unread message

Faye

unread,
Apr 10, 2019, 9:20:56 PM4/10/19
to Google Apps Script Community

Ok so I posted that I needed help with creating a script in a different site forum called stackoverflow and someone gave me a script which basically created a brand new sheet with what I needed done but it wasn't exactly what I needed. I already have a Spreadsheet in which I have multiple sheets. On one of those sheets I would like to create a script that would auto-populate today's date in one column upon entering or editing data in another column. So what I am looking for is I have a Spreadsheet with multiple sheets one of those is called "Juvenile weights" (without the "" of course just making sure you understand this) so I need the scripts to identify that sheet and when I edit any cell within column G, I need the adjacent cell in column H to auto-populate with the current date. 


I have absolutely no understanding of scripting and I am completely lost. I have tried everything everyone suggested for the particular script he gave me but it is not working for the sheet I am trying to use. So if there is anyone who can create a script for me to do this I would be very grateful to you. If you need the name of the entire Spreadsheet it is called Husbandry Log. It is a set of sheets that helps me keep track of certain data for my business of breeding and selling corn snakes. In this particular sheet I am trying to keep track of my juvenile weights as they are growing and being raised to be breeders. PLEASE HELP!!!!!!!!


Below is a screenshot of the sheet I am working with and below that is a screenshot of the script I was using which obviously isn't working for what I need. It keeps giving me an error which is also included in the screenshot of the app.


screenshot-docs.google.com-2019.04.09-16-00-56.jpg


screenshot-script.google.com-2019.04.09-15-30-38.jpg


Federico Granata

unread,
Apr 11, 2019, 4:53:40 AM4/11/19
to google-apps-sc...@googlegroups.com
If you try to manually run the "onEdit" function you aren't providing an "event" argument so it's undefined and you get that error.
For debugging purpose you can create another function that call the "onEdit" passing an argoument with the object you are expecting. 

___
+FedericoGranata


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/797ac0f9-fb72-4576-81a3-26c4b552464e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reno Blair

unread,
Apr 11, 2019, 12:47:29 PM4/11/19
to google-apps-sc...@googlegroups.com
As Federico said, there is no event object passed to the function if you just test it directly. You could test by building a custom event object, or by getting the event to fire normally (by making an edit to the spreadsheet).

Here is another script to update column H with a new Date object any time there is an edit in column G on the same row. You will need additional logic if you don't want it to overwrite existing values, or any other specific cases. You can format the column from the interface, so that the inserted dates will have your preferred format.

function onEdit(event) {
var watchSheet = "Juvenile weights";
var watchColumn = "G";
var targetColumn = "H";
var sheet = event.range.getSheet();
var [,columnLetter, row] = /^([a-z]+)([0-9]+)$/i.exec(event.range.getA1Notation());
if (sheet.getName() === watchSheet && columnLetter === watchColumn) {
sheet.getRange(targetColumn + row).setValue(new Date());
}
}



For more options, visit https://groups.google.com/d/optout.


--
Reno Blair
Educational Technology Services​
Reply all
Reply to author
Forward
0 new messages