The program basically collects information through Appsheet and stores its data into a sheet, BUS PASSENGER DETAILS SHEET, on application submit. Then, using the function below, It sorts it out on a table based on the Trip Number on a daily basis.
There are 2 more Functions the same as sortGender()
that sorts out data depending if a individual is a Senior Citizen or a PWD (Person with Disabilities) but we will leave that out and focus on one sheet.
I am seeking insight with my code regarding the array I made for me to use to redirect data to where I need it to be. An example of this array is this
const sheetRanges = {
"1": {male: "C12", female: "D12"},
"2": {male: "E12", female: "F12"},
"3": {male: "G12", female: "H12"},
"4": {male: "I12", female: "J12"},
"5": {male: "K12", female: "L12"},
"6": {male: "M12", female: "N12"},
"7": {male: "O12", female: "P12"},
"8": {male: "Q12", female: "R12"},
"9": {male: "S12", female: "T12"},
"10": {male: "U12", female: "V12"},
"11": {male: "W12", female: "X12"},
"12": {male: "Y12", female: "Z12"},
"13": {male: "AA12", female: "AB12"},
"14": {male: "AC12", female: "AD12"},
"15": {male: "AE12", female: "AF12"}
};
this is then applied to
function sortGender(callback){
var range = sheetNameDAVAO1.getRange(lastrow_davao1, 1, 1, 5);
var value = range.getValues();
Logger.log(value);
value.forEach(x => {
var currentTripNumber = values[1];
var currentGender = values[3];
if (currentTripNumber in sheetRanges && currentGender == "Male") {
var maleRange = sheetNameOverall.getRange(sheetRanges[currentTripNumber].male);
Logger.log(currentTripNumber);
var addMale = maleRange.getValue() + 1;
maleRange.setValue(parseInt(addMale));
sheetNameMonthly.getRange("X10").setValue(parseInt(addMale));
sheetNameOverall.getRange("J8").setValue(parseInt(addMale));
} else if(currentTripNumber in sheetRanges && currentGender == "Female") {
var femaleRange = sheetNameOverall.getRange(sheetRanges[currentTripNumber].female);
var addFemale = femaleRange.getValue() + 1;
femaleRange.setValue(parseInt(addFemale));
sheetNameMonthly.getRange("X11").setValue(parseInt(addFemale))
sheetNameOverall.getRange("J8").setValue(parseInt(addFemale));
}
});
callback()
}
The sheet ranges from C12:AF12 and that is the first line of 31 rows which means the list goes on from C12:AF42. C12:AF12 runs for day 1, then C13:AF13 for day 2, and so on which gives me the task to efficiently store an array as big as this.
How can I approach this in a way that it efficiently gives me the arrays I need from day 1 to 31, from C12:AF12 to C42:AF42 daily until the end of the month?
The code above perfectly works and sorts out the data where I need it to be but sadly it only does until the first line and I don't have anything to cover all of the remaining cells below (C13:AF42).
I was thinking of creating a JSON file to store it just like the array I mentioned above from C12:AF12 for day 1 to C42:AF42 for day 31 but haven't got a clue on as to how to structure it in the JSON File and to utilize it in Google Apps Script. I have tried yes but not at this scale.
Sample of the link with code on Apps Script: https://docs.google.com/spreadsheets/d/19rluTp6-tQmiA13mTOF4KmK2ED5NP1WCSjWdZYBj1pE/edit?usp=sharing