I have a script with a time based trigger that makes a backup copy of a spreadsheet every evening.
However, the sheet isn't modified on weekends or some weekdays, at all.
I want to exit the DUPLICATESHEET script if the document (google sheet) wasn't opened or modified that day.
I'd prefer to do it WITHOUT having to write "last modified" in a cell somewhere.
I can get it to work by writing a last modified script to a cell, and then checking that cell with the script.
However, I'm hoping there is a way to just use the script to check the Google Sheet metadata to see the LastModified or LastOpened date. If it wasn't opened within last 24 hours, then exit the script.
Sort of a code newbie
var FILE_ID = 'FILE_ID';
var LastUpdatedPerDrive = DriveApp.getFileById(FILE_ID).getLastUpdated();
//if currentDateTime - lastUpdatedDateTime is more than 1 day (more than 24 hours since last update) then exit the script.
if (new Date() - LastUpdatedPerDrive > 1 * 24 * 60 * 60 * 1000) {
return;
//EXIT THE FUNCTION and do not proceed with below
}
Not really sure how to do this. https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet Doesn't seem to have a LastModified
Maybe I have to use the Drive app, like this How to get Google docs last edit date