I am very new to Javascript and Apps Script. I want to create a function that updates another sheet based on a date in a certain range of the active sheet. I run and no error but it doesn't transfer value from active sheet to sheet named "January", in different target url google sheet
function myFunction4() {
const spreadsheetIds = [
{ id: "1ShPxDW9qhz4aWgaQ1G9oz7w1yh0-Wfe2VItet95UYks", sheetNames:
["cab1"] },
{ id: "13Dx3ZOpV7baSTadSApIrVVccN-bHrPlHu240Aux0fo0", sheetNames:
["cab2"] },
{ id: "14EVlqaP1ilXwopgi0ESvp_IKkSyROSF22WzWAcNAJWc", sheetNames:
["cab3", "cab4"] }
];
const srcSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const srcSheet = srcSpreadsheet.getSheetByName("January");
if (!srcSheet) return;
const date = new Date();
const ssName = srcSpreadsheet.getName();
const range = srcSheet.getRange("A2:C" + srcSheet.getLastRow());
let values = range.getValues();
if (values.filter(r => r.join("")).length == 0) return;
values = values.map(r => [...r, date, ssName]);
range.clearContent();
for (let i = 0; i < spreadsheetIds.length; i++) {
const dstSpreadsheet = SpreadsheetApp.openById(spreadsheetIds[i].id);
for (let j = 0; j < spreadsheetIds[i].sheetNames.length; j++) {
const targetSheet =
dstSpreadsheet.getSheetByName(spreadsheetIds[i].sheetNames[j]);
if (targetSheet) {
targetSheet.getRange(targetSheet.getLastRow() + 1, 1, values.length,
values[0].length).setValues(values);
}
}
}
}
copyto Google Sheets Script adding date and source data in the next column
I want when I click the send button. can add Date and source in the next column
Date = date when sent
source = the name of the workbook that sent it
otherSheetName.getRange(1,getJumlahKolom+1).setValue("Date").setFontWeight("bold").setHorizontalAlignment("center");
otherSheetName.getRange(1,getJumlahKolom+2).setValue("source").setFontWeight("bold").setHorizontalAlignment("center");
Date & source, the function you want to join to myFunction3()
but it doesn't transfer value from active sheet to sheet named "January". But, in your added sample, it seems that the values from the "January" sheet of Spreadsheet "A" is copied to "cab1" sheet of Spreadsheet "B". And, in your added script, "January" sheet is not used. As the result, what is your actual expected result? I'm confused. I apologize for this.