I've just created a script in google spreadsheet in order to archivate some things. I've got datas from four countries, and if something is marked done, then that line could be archived into that countries archive. My code is pretty ugly :). Is there a clearer way to do this? And also it would be great if someone could give me a little help with a thing. I want to do the archivation daily, and add to the countries archive. But after a month, I want to start another sheet for that month's daily backups. How can I do that? Thanks in advance... An here comes the code:
function CroatianArchive()
{
var source_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('original');
var target_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('croatian_backup');
var lastRow = source_sheet.getLastRow();
var source_range = source_sheet.getDataRange();
var target_range = target_sheet.getDataRange();
var rowsToBeDeleted = [];
var i = 2;
while (i <= lastRow) {
if (source_sheet.getRange("A"+i).getValue() == "CRO" && source_sheet.getRange("M"+i).getValue() == "DONE" ) {
var office = source_sheet.getRange("A"+i).getValue();
var title = source_sheet.getRange("B"+i).getValue();
var imdbId = source_sheet.getRange("C"+i).getValue();
var channel = source_sheet.getRange("D"+i).getValue();
var type = source_sheet.getRange("E"+i).getValue();
var added = source_sheet.getRange("F"+i).getValue();
var deadline = source_sheet.getRange("G"+i).getValue();
var airing = source_sheet.getRange("H"+i).getValue();
var link = source_sheet.getRange("I"+i).getValue();
var picture = source_sheet.getRange("J"+i).getValue();
var comment = source_sheet.getRange("K"+i).getValue();
var portId = source_sheet.getRange("L"+i).getValue();
var status = source_sheet.getRange("M"+i).getValue();
var data = [office,title,imdbId,channel,type,added,deadline,airing,link,picture,comment,portId,status];
target_sheet.appendRow(data);
rowsToBeDeleted.push(i);
i++;
} else {
i++;
}
}
rowsToBeDeleted.reverse();
for (var j = 0; j < rowsToBeDeleted.length; j++)
{
source_sheet.deleteRow(rowsToBeDeleted[j]);
}
SpreadsheetApp.getActiveSpreadsheet().toast('Archivation finished.', 'Status');
}
function SerbianArchive()
{
var source_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('original');
var target_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('serbian_backup');
var lastRow = source_sheet.getLastRow();
var source_range = source_sheet.getDataRange();
var target_range = target_sheet.getDataRange();
var rowsToBeDeleted = [];
var i = 2;
while (i <= lastRow) {
if (source_sheet.getRange("A"+i).getValue() == "SER" && source_sheet.getRange("M"+i).getValue() == "DONE" ) {
var office = source_sheet.getRange("A"+i).getValue();
var title = source_sheet.getRange("B"+i).getValue();
var imdbId = source_sheet.getRange("C"+i).getValue();
var channel = source_sheet.getRange("D"+i).getValue();
var type = source_sheet.getRange("E"+i).getValue();
var added = source_sheet.getRange("F"+i).getValue();
var deadline = source_sheet.getRange("G"+i).getValue();
var airing = source_sheet.getRange("H"+i).getValue();
var link = source_sheet.getRange("I"+i).getValue();
var picture = source_sheet.getRange("J"+i).getValue();
var comment = source_sheet.getRange("K"+i).getValue();
var portId = source_sheet.getRange("L"+i).getValue();
var status = source_sheet.getRange("M"+i).getValue();
var data = [office,title,imdbId,channel,type,added,deadline,airing,link,picture,comment,portId,status];
target_sheet.appendRow(data);
rowsToBeDeleted.push(i);
i++;
} else {
i++;
}
}
rowsToBeDeleted.reverse();
for (var j = 0; j < rowsToBeDeleted.length; j++)
{
source_sheet.deleteRow(rowsToBeDeleted[j]);
}
SpreadsheetApp.getActiveSpreadsheet().toast('Archivation finished.', 'Status');
}