I have a script that is set to run whenever a trigger is sent, and it needs to sort through the data it receives to determine which sheet to write data to.
I used to hard-code it with the exact names and it worked fine, but now I'm trying to make it easier to scale. Variable value in the switch should be a number.
Below is a snippet of the code.
var myIds = [111, 222, 333, 444];
var myUsers = ['aaa', 'bbb', 'ccc', 'ddd'];
...
switch (param) {
case 1:
break;
case 2:
for (let i = 0; i < myIds.length; i++) {
if (value == myIds[i]) {
userName = myUsers[i];
break;
}
}
userName = 'ETC';
break;
}
if (userName != 'ETC') {
let inSheet = 'In ' + userName;
let outSheet= 'Out ' + userName;
if (checkIn == true)
sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheetByName(inSheet));
else
sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheetByName(outSheet));
}
else
sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheetByName('ETC'));
Rather than going to their respective In / Out sheets, everything goes to the ETC sheet instead. Some other times, there would not be any change on the sheets at all. It would be greatly appreciated if someone could explain why this happens, in addition to the question.
Thanks in advance.