How to add timestamp to another spreadsheet every time an update is made on a separate spreadsheet

19 views
Skip to first unread message

Tom Bergdahl

unread,
Sep 15, 2021, 3:47:52 AM9/15/21
to Google Apps Script Community
Hi, 

I created this spreadsheet where every time it updates it will generate a timestamp to another spreadsheet linked via URL. The problem is that the timestamp did not generate to the spreadsheet that i have linked with the google script.

Here is the code that i have been working on :


function onEdit(e) {

  addTimestamp(e);
  
}

function addTimestamp(e){

  var row = e.range.getRow();
  var col = e.range.getColumn();

  if(col >= 1 && col <= 3  && row > 1 && e.source.getActiveSheet().getName() === 'fillForm'){
  
    var currentDate = new Date();



  }


}


Did i do something wrong or is there a work around for this problem?

Thank You,
Tom

Chanel Greco

unread,
Sep 15, 2021, 7:10:47 AM9/15/21
to Google Apps Script Community
Hi Tom

Have you tried running this in the Debug mode to see where the problem could be? For instance, does the if conditional evaluate to true and then enter the code block?

Here a video on how to debug that might be helpful: https://youtu.be/L4V15ZxIjBQ

Chanel

cbmserv...@gmail.com

unread,
Sep 15, 2021, 4:56:14 PM9/15/21
to google-apps-sc...@googlegroups.com

Debug mode would not work because he is using environment variables. But if you simulate the e variable, you can try debug.

 

One thing you should do is check the URL you are using. Not sure this is a valid URL for the purposes of the openByURL method. It may be easier to use openById and use the id which is:

 

1sEwHbKVO7rjbQuEiA6vXN7imn_y072lkgc6q84fNxkw

 

This forms part of the URL you are using in the script.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/57e9e9da-3d8d-4222-864c-35c5867c7ed4n%40googlegroups.com.

Emerson Maia

unread,
Sep 19, 2021, 4:31:50 AM9/19/21
to google-apps-sc...@googlegroups.com
 

Good morning, try using the map



 let currentDate = new  Date ()

if (col> = 1 && col <= 3 &&  row> 1 && e.source. getActiveSheet (). getName () ===  'fillForm') {
  
   const values = currentDate

sheet.getRange(2, 1, values.length, values[0].length).setValues(values)



{

--
Reply all
Reply to author
Forward
0 new messages