Reputation: 1
I have two sheets, 1. sourceData 2. Done sourceData has one column that is either marked 'ACTIVE' or a is a 'Date' value. What I want to do is to move those rows with column marked ACTIVE to another sheet called 'DONE'. I wrote a script here which works in transferring the data, but rows from the sheet 'ACTIVE' will be transferred over and over again if i run this script on a schedule. Is there any way to remove the rows once they have been transferred? or change the cell value of 'ACTIVE' to something else so that it fails the filterLogic? Any help is welcomed, thank you!
function tsfActive() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var pr = ss.getSheetByName("sourceData");
var ts = ss.getSheetByName("DONE");
var originalData = pr.getRange(2,1,pr.getLastRow()-1,3).getValues();
var data = originalData.filter(filterLogic);
Logger.log(data);
ts.getRange(ts.getLastRow()+1,1,data.length,3).setValues(data);
}
var filterLogic = function(item){
if(item[1] === "ACTIVE"){
return true;
}
else{
return false;
}
}
Upvotes: 0
Views: 47
Reputation: 64100
I think this does it:
function tsfActive() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var pr = ss.getSheetByName("sourceData");
var ts = ss.getSheetByName("DONE");
var od = pr.getRange(2,1,pr.getLastRow()-1,3).getValues();
var data=od.map(function(r){return r;}).filter(function(r){return r[1]=='ACTIVE'});
Logger.log(data);
ts.getRange(ts.getLastRow()+1,1,data.length,3).setValues(data);
}
Upvotes: 1