I have an archiving script which is now working as it should (I have included it below). However I would like it to run only at 1 am on the date the sheet is in use for.I make the sheets and name them months in advance and they sit in drive until the day of use (maybe earlier if we get pre bookings) but i don't want them to run the script and archive every night at 2 AM! Is there any way to make the time driven trigger only once? At moment the time driven trigger doesn't copy over when i copy the blank sheet either. Any ideas or a better way of automating this? Thanks.
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS =
SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A2').getValue(); // Changed to stop
inadvertent cell changes, also made text white so not seen.
var data =
inputSheet.getRange('E7:U37').getValues().filter(function(row) { return
row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(),
1).getValue();
var maxRowLength = data.reduce(function(length, row) { return
Math.max(length, row.length); }, 0);
var date = new Date(date);
var getDate = new Date(getDate);
if (getDate.getDate() != date.getDate() || getDate.getMonth() !=
date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(),
data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1,
data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1,
2).setValues([[date, 'No Data']]);
}
}
}
}
Set your trigger to only go off once monthly? E.g. Weekly or set date?
As for triggers copying over they won't due to the way Google have made their service. Doesn't take long to set them up.
Related
I have the following script that needs to run at the end of the relevant day, I have tried to get it to run on a timer and I can't work it out. I have 5 sheets which are for different parts of the day to schedule the staff. At the end of the day I need to send it to a master sheet that tallies hours worked and various tasks worked on. My issues are:-
1) I have a blank Google Worksheet with 5 sheets inside it + 1 hidden sheet. This needs to be sent to the master copy on the day of its' name, automatically if possible.
2) They can be made up to 3 months in advance and don't want it sending a blank back up daily.
3) When I press "backup" button on any newly created sheet I have to authorise the script.
Is there any way to not have to authorise the script on the new spreadsheet. Does anyone have a better idea for automating this?
function onOpen() { // This function adds a custom menu to the spreadsheet (Backup to archive) so you can run the script from there.
var ui = SpreadsheetApp.getUi();
ui.createMenu('Backup')
.addItem('Backup','dataBackup')
.addItem('Name','nameOfSpreadsheet')
.addToUi();
}
function nameOfSpreadsheet() {
var s=SpreadsheetApp.getActive().getName().replace(/(\d{1,2}\.\d{1,2}\.\d{1,2}).*/,'$1');
return s;
}
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS = SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A2').getValue(); // Changed to stop inadvertent cell changes, also made text white so not seen.
var data = inputSheet.getRange('E7:U37').getValues().filter(function(row) { return row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
var maxRowLength = data.reduce(function(length, row) { return Math.max(length, row.length); }, 0);
var date = new Date(date);
if (date.getDate() === "Loading Data...") {
Utilities.sleep(10000);
SpreadsheetApp.flush();
if (getDate.getDate() != date.getDate() || getDate.getMonth() != date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]);
}}}}}
It doesn't make sense to me to put nameofSpreadsheet in the menu .addItem('Name','nameOfSpreadsheet'). It doesn't accomplish anything because there's no way to see the return.
I took a stab at rewriting your backup function.
function dataBackup()
{
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS = SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i=0; i<sheetNames.length; i++)
{
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date=new Date(inputSheet.getRange('A2').getValue());
var rng=inputSheet.getRange('E7:U37');
var dataA=rng.getValues();
var data=[];
for(var j=0;i<dataA.length;j++)
{
if(dataA[j][0] && dataA[j][1])
{
data.push([dataA[j].splice(0,0,date)]);
}
}
var dv=archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
date=(typeof(dv)!='undefined')?dv:'No Date Found';
if (data.length>0)
{
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, rng.getWidth()+1).setValues(data);
}
else
{
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]);
}
}
}
My spreadsheet for containing the archived information
Sample of daily sheet that needs archiving
I have the code below that is used to insert a menu button so it can be manually backed up at end of day, see below.
When I copy this daily sheet using a script it keeps all the information but I have to authorise every sheet to run script.
My question is can I make the script run without any authorisation or is there another way to automate the sending of the data from 4 of the 6 sheets to the corresponding sheets on the archive sheet?
As it is a collaboration if I am away or off no-one else can authorise the script.
How would YOU handle this?
Thank you in advance.
function onOpen() { // This function adds a custom menu to the spreadsheet (Backup to archive) so you can run the script from there.
var ui = SpreadsheetApp.getUi();
ui.createMenu('Backup')
.addItem('Backup','dataBackup')
.addToUi();
}
function nameOfSpreadsheet() {
var s=SpreadsheetApp.getActive().getName().replace(/(\d{1,2}\.\d{1,2}\.\d{1,2}).*/,'$1');
return s;
}
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS = SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A2').getValue(); // Changed to stop inadvertent cell changes, also made text white so not seen.
var data = inputSheet.getRange('E7:U37').getValues().filter(function(row) { return row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
var maxRowLength = data.reduce(function(length, row) { return Math.max(length, row.length); }, 0);
var date = new Date(date);
var getDate = new Date(getDate);
if (getDate.getDate() === "Loading Data...") {
Utilities.sleep(30000);
}
if (getDate.getDate() != date.getDate() || getDate.getMonth() != date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]);
}
}
}
}
I have a daily worksheet titled 07.09.17 Thursday, there are 4 sheets inside that I would like to add 07.09.17 (or the day of the sheet) in cell A1? Obviously every day is dated accordingly but when running a back up script I want it to refer to cell A1 as the date to be entered into the archive sheet. I have everything else working except this. I can't us =Now() or =Today() as I make the sheets up to 3 months in advance as we have some bookings that far in advance, also they are not only accessed on that day but many days.However the day of the backup is the date of the sheet.With many staff I don't want to have to trust them to do (ctrl) +; to insert date for each sheet manually.
Thank you for your help.
function onOpen() { // This function adds a custom menu to the spreadsheet (Backup to archive) so you can run the script from there.
var ui = SpreadsheetApp.getUi();
ui.createMenu('Backup to archive')
.addItem('timeStamp','dataBackup')
.addToUi();
}
function timeStamp() {
SpreadsheetApp.getActiveSheet()
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
.setActiveCell()
.setValue(new Date());
}
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS = SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A1').getValue();
var data = inputSheet.getRange('E7:U37').getValues().filter(function(row) { return row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
var maxRowLength = data.reduce(function(length, row) { return Math.max(length, row.length); }, 0);
var date = new Date(date);
var getDate = new Date(getDate);
if (getDate.getDate() != date.getDate() || getDate.getMonth() != date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]);
}
}
}
}
Assuming that the sheets that you want this in are in the same spreadsheet then all you have to do is go to A1 and enter this =nameOfSpreadsheet() Yes, I know it's customary to capitalize all of the letters but I generally swim against the currents of following customs. You may capitalize all of them if you wish.
function nameOfSpreadsheet()
{
return SpreadsheetApp.getActive().getName();
}
All of course you will have to put the function into a project in your script editor. I keep my custom functions like this in a separate project from other functions.
I didn't pay attention to removing the week day so I find that this will work for that and now you just get the date.
function nameOfSpreadsheet()
{
var s=SpreadsheetApp.getActive().getName().replace(/(\d{1,2}\.\d{1,2}\.\d{1,2}).*/,'$1');
return s;
}
This is the function in the code editor:
And this is how it's deployed:
The title of the spreadsheet is 09.09.17 Saturday
I have an archiving script which is now working as it should, however when backing up I did get correct date from cell A2 in first sheet but in the other 3 sheets I get 01/01/1970 in date stamp column on archive sheet. So I assume I need to pause script to allow new page to load date in A2 from sheet name. I have added a pause in line 33 but now i am getting 01/01/70 in all sheets! I have now let it run overnight and when I checked this am I have 01/0/1970 in ll 4 sheets so I am assuming the delay is either not enough or in the wrong place in the script, can anyone help please?
function onOpen() { // This function adds a custom menu to the
spreadsheet (Backup to archive) so you can run the script from there.
var ui = SpreadsheetApp.getUi();
ui.createMenu('Backup')
.addItem('Backup','dataBackup')
.addToUi();
}
function nameOfSpreadsheet()
{
var s= SpreadsheetApp.getActive().getName().replace(/(\d{1,2}\.\d{1,2}\.\d{1,2}).*/,'$1');
return s;
}
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS =
SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A2').getValue(); // Changed to stop
inadvertent cell changes, also made text white so not seen.
var data =
inputSheet.getRange('E7:U37').getValues().filter(function(row) { return
row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(),
1).getValue();
var maxRowLength = data.reduce(function(length, row) { return
Math.max(length, row.length); }, 0);
var date = new Date(date);
var getDate = new Date(getDate);
if (getDate.getDate() === "Loading Data...") {
Utilities.sleep(10000);
}
if (getDate.getDate() != date.getDate() || getDate.getMonth() !=
date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(),
data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1,
data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1,
2).setValues([[date, 'No Data']]);
}
}
}
}
I have a script entered below which I am trying to use on a daily worksheet with multiple pages, I have an archive sheet where the information is meant to be copied across at end of business. Both sets of sheets are named identical to ease back up. However I get a lot of blank lines with the date entered and not the other information. I have a Menu UI to add a button for the staff to do a back up at end of day as well, again to make life easier. I do also have a few other scripts attached to the file so not sure if (most likely the "Font and Alignment" script is causing an issue.
Can anyone see what I am doing wrong?
function menu() { // This function adds a custom menu to the spreadsheet (Backup to archive) so you can run the script from there.
var ui = SpreadsheetApp.getUi();
ui.createMenu('Backup to archive')
.addItem('Backup', 'dataBackup')
.addToUi();
}
function dataBackup() {
var check = alert("Data Backup","Are you sure you want to backup today's entries?");
if(!check){ return; }
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var date = inputSheet.getRange('A1').getValue(); // Gets todays date from cell A1
var dataLen = inputSheet.getRange('E7:A37').getValues().filter(String); // Gets the number of entries made today
var dataRange = inputSheet.getRange('E7:U37'); // Gets the range of cells A7:U37
var data = dataRange.getValues().slice(0, dataLen.length); // Removes any rows that don't have a number in the '#' column
for (var x = 0; x < data.length; x++) { // Adds todays date to the start of each row.
var temp = data[x].splice(0, 0, date)
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
if (getDate != date) { // Checks for duplicate backup
if (data.length != 0) { // If there are entries with todays date
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length); // Inserts the required amount of rows
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, data[0].length).setValues(data).setNumberFormat("#"); // inserts the data to the archive sheet
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1); // If there was no data, inserts 1 row
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]); // Inserts todays date and 'No Data'
}
}
}
}
function alert(title, message)
var ui = SpreadsheetApp.getUi();
var alert = ui.alert(title, message, ui.ButtonSet.YES_NO);
var response;
if(alert == "YES"){
response = true
} else {
response = false
}
return response;
}
The link below is for the archive sheet:-
https://docs.google.com/spreadsheets/d/146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g/edit?usp=sharing
Below is a sample of an input sheet:-
https://docs.google.com/spreadsheets/d/1XwPFgVP_DlsBp4Th8pR7qKvx4Bh1zUubHabgMdDD3ck/edit?usp=sharing
Thank you.
Below is the now working backup script. I have an odd issue though that the menu button isn't appearing until I call it manually from the script editor? Each time I am asked to review permissions but never had that issue before, is it because of another running script? Maybe the font alignment one?
}
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS = SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A1').getValue();
var data = inputSheet.getRange('E7:U37').getValues().filter(function(row) { return row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
var maxRowLength = data.reduce(function(length, row) { return Math.max(length, row.length); }, 0);
var date = new Date(date);
var getDate = new Date(getDate);
if (getDate.getDate() != date.getDate() || getDate.getMonth() != date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]);
}
}
}
#SpiderPig OK, it was working and now I am not sure what the issue is with the script below. I have adjusted worksheet name cell to A2 to avoid inadvertent removal as A1 is the active cell when opening and have had instances where stuff gets typed there. But now in the archive sheet I get the date 01/01/1970 even though A2 has 01.01.18. The no data is correct. I have tried changing column to Date format and made sure input sheet is Date formatted. I also have to authorise the script each time but don't want to do that if I can help it. Can I run the script on a time trigger say at 2AM, would this still need authorising for each copy I make. Want to make a copy for each day of the year with the correct day / date name.
function onOpen() { // This function adds a custom menu to the spreadsheet (Backup to archive) so you can run the script from there.
var ui = SpreadsheetApp.getUi();
ui.createMenu('Backup')
.addItem('Backup','dataBackup')
.addToUi();
}
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS =
SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A2').getValue(); // Changed to stop
inadvertent cell changes, also made text white so not seen.
var data =
inputSheet.getRange('E7:U37').getValues().filter(function(row) { return
row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(),
1).getValue();
var maxRowLength = data.reduce(function(length, row) { return
Math.max(length, row.length); }, 0);
var date = new Date(date);
var getDate = new Date(getDate);
if (getDate.getDate() != date.getDate() || getDate.getMonth() !=
date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(),
data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1,
data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1,
2).setValues([[date, 'No Data']]);
}
}
}
}
I tried to improve the script a bit. I also changed the way dates are compared since I felt the old way may not work reliably.
function dataBackup() {
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS = SpreadsheetApp.openById('146WU8RghfFqlCpCSX7n6kBAKOyxcpVKt14yhVfvYz-g');
var user = Session.getActiveUser().getEmail();
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i = 0; i < sheetNames.length; i++) {
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date = inputSheet.getRange('A1').getValue();
var data = inputSheet.getRange('E7:U37').getValues().filter(function(row) { return row[0] !== '' || row[1] !== ''});
for (var x = 0; x < data.length; x++) {
data[x].splice(0, 0, date);
}
var getDate = archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
var maxRowLength = data.reduce(function(length, row) { return Math.max(length, row.length); }, 0);
if (getDate.getDate() != date.getDate() || getDate.getMonth() != date.getMonth()) {
if (data.length != 0) {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, maxRowLength).setValues(data);
} else {
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]);
}
}
}
}