I have the following script:
function send_purchase_invoices() {
var ss = SpreadsheetApp.getActive();
var srcSheet = ss.getSheetByName("MAIN");
var dstSheet = ss.getSheetByName("purchase_invoices");
var data_range = srcSheet.getRange('DK4:DR18');
var data_data = data_range.getValues();
var data_clean = data_data.filter(function (r) {return !r[0]});
var lr = dstSheet.getLastRow();
dstSheet.getRange(lr+1, 1,data_clean.length,8).setValues(data_clean);
srcSheet.getRange(data_clean).setValues('SUBMITTED');
}
This line here:
srcSheet.getRange(data_clean).setValues('SUBMITTED');
I'm trying to call the data range set in this section:
var data_range = srcSheet.getRange('DK4:DR18');
var data_data = data_range.getValues();
var data_clean = data_data.filter(function (r) {return !r[0]});
Or, more specifically, column [0] as defined here:
var data_clean = data_data.filter(function (r) {return !r[0]});
So that it populates the word "SUBMITTED" to those cells.
Any constructive advice, greatly appreciated.
I believe your goal is as follows.
SUBMITTED
into the cells of column "DK" when the value of column "DK" is empty.Although I'm not sure whether I could correctly understand your expected result, how about the following modification?
function send_purchase_invoices() {
var ss = SpreadsheetApp.getActive();
var srcSheet = ss.getSheetByName("MAIN");
var dstSheet = ss.getSheetByName("purchase_invoices");
var data_range = srcSheet.getRange('DK4:DR18');
var data_data = data_range.getValues();
var data_clean = data_data.filter(function (r) { return !r[0] });
var lr = dstSheet.getLastRow();
// I modified the below script.
if (data_clean.length == 0) return;
dstSheet.getRange(lr + 1, 1, data_clean.length, 8).setValues(data_clean);
const rangeList = data_data.reduce((ar, [a, ...b], i) => {
if (!a && b.join("")) {
ar.push(`DK${i + 4}`);
}
return ar;
}, []);
srcSheet.getRangeList(rangeList).setValue('SUBMITTED');
}
SUBMITTED
is put into the cells of column "DK" when the cell of column "DK" is empty.