I have a spreadsheet that allows volunteers to call and request cases to work. Once they call, a lead volunteer will simply enter their email, a date and how many cases they want assigned to them.
Each sheet in the spreadsheet is prepopulated with an avg of 200 cases (case information starts in column F of every sheet and there are over 50 sheets.) Volunteers can request 1 to 50 cases at any given time. Currently, I have it set up where the lead will choose the volunteer from a drop down and there's a script that will email. However, it is cumbersome if the volunteer wants the max cases. The lead has to select the name too many times.
I have 2 working functions:
- Function: f_boxesChecked captures 1 row for each volunteer per day. It simply has a checkbox to email to Agent, Agent's name, and quantity (columns B-D). It is entered into the 1st available case. Each agent will get 1 row entered per day. At the end of the day, the last lead volunteer will send all the emails out (via a script that works when I manually enter the data. I do not need help with that)
- Problem 1: I can see the correct data in the log, but I am unable to use setValue or setValues nor copyTo and it show up on the sheet.
- Problem 2: Since I want the records to autogenerate based on the quantity, I don't know how to loop it.
function
f_boxesChecked() { var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var rows = SpreadsheetApp.getActiveSheet().getRange("B3:D").getValues();
var headers = rows.shift();
var lr =f_lrInRange(ss,"B1:D");
rows.forEach(function(data) {
if(data[0]) {
var qty= data[1]-1;
Logger.log(lr);
Logger.log(data);
//return (data);
}
});
}
Since the spreadsheets are prepopulated with everything except agent data, I have successfully created a function that captures the last row within the range B1:D It is called f_lrInRange. I know I need that piece of information to tell the loop where to start inserting the records.
function f_lrInRange(sheet,rangeString){
var rng = sheet.getRange(rangeString).getValues();
var lrindex;
for
(var i = rng.length-1;i>=0;i--){
lrindex = i;
if(!rng[i].every(function(c){return c == "";})){
break;
}
}
return lrindex + 1;
}
Please help. I have attached the link to the spreadsheet. I would greatly appreciate any help at all. On the spreadsheet, Sheet-Current Process shows what a blank sheet looks like when it is assigned to a lead volunteer. Sheet-Desired Process is what I would like to happen.
Thanks