How to make .map() ignore values in array. In script below values in column B and C of dstSheet are erased when running script. I want to keep it. How to modify this script?
function dorozliczenia() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const srcSheet = ss.getSheetByName("arkusz 1");
const dstSS = SpreadsheetApp.openById("1bjqauqiyEzUkECaxqswRmOQPYWydpSAvLf97t5ovbXQ");
const dstSheet = dstSS.getSheetByName("arkusz 1");
const obj = Object.fromEntries(srcSheet.getRange("A2:C" + srcSheet.getLastRow()).getValues().map(([a, , c]) => [c, a]));
const dstRange = dstSheet.getRange("A2:D" + dstSheet.getLastRow());
const values = dstRange.getValues().map(([, , , a]) => [obj[a] ? true : false,null ,null , a]);
dstRange.setValues(values);
}
Here are the spreadsheets:
https://docs.google.com/spreadsheets/d/1bjqauqiyEzUkECaxqswRmOQPYWydpSAvLf97t5ovbXQ/ https://docs.google.com/spreadsheets/d/11ZVtFJ5Ul5nUu3PLxUu_xBlfS0bbeAWRj8-ZKwKUTG8/
2
Answers
In your script, how about the following modification?
From:
To:
I thought that the reason for your current issue might be due to
null ,null
of[obj[a] ? true : false,null ,null , a]
. So, the current value is used as this modification.Or, how about putting only the values of column "A" as follows?
To modify the script to keep the values in columns B and C of the
dstSheet
when running the script, you can adjust the code that creates thevalues
array. Currently, the script is only creating a new array with a boolean value and the value from column A for each row in thedstSheet
, effectively erasing the values in columns B and C.To keep the values in columns B and C, you can modify the code that creates the values array to include the existing values from those columns.