Home > Mobile >  Using Google Script I want to add a timestamp to each row of the result
Using Google Script I want to add a timestamp to each row of the result

Time:09-07

I want to add a timestamp to each row of the result. I have attempted to add a separate timestamp script on edit but that is not working. Below is the code I am using.

function importCSVFromGmail() {

 var threads = GmailApp.search("Gmail Search"); 
 var message = threads[0].getMessages();
 var attachment = message[message.length - 1].getAttachments()[1];


 var sheet = SpreadsheetApp.openById('SHEET ID'); 
 var tab = sheet.getSheetByName('Data');

 var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");

 var startRow = sheet.getLastRow();

 var dataRange = tab.getRange(startRow,1,csvData.length, 
 csvData[0].length).setValues(csvData);


 }

CodePudding user response:

function importCSVFromGmail() {
  var threads = GmailApp.search("Gmail Search");
  var message = threads[0].getMessages();
  var attachment = message[message.length - 1].getAttachments()[1];
  var sheet = SpreadsheetApp.openById('SHEET ID');
  var tab = sheet.getSheetByName('Data');
  var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");
  let o = csvData.map(r => {
    let x = r.slice();
    x.push(new Date());
    return x;
  }})
  var startRow = sheet.getLastRow();
  tab.getRange(startRow, 1, o.length, o[0].length).setValues(o);
}
  • Related