I have a list of data:
I wrote a script that will move that data into my database placing the date in the appropriate column after finding the row with the person's name. I would like to adjust my script so that it skips any rows that don't have a date in the 3rd column. In my above example it would update Brad & Chris' records, skip Dana update David, skip Gabi and update Jacob.
As I've written it now the program takes about 20 seconds per record to search the existing database before adding the date. Since the list usually includes 40-50 names with only 4 or 5 having dates with them if I could make it skip empty rows that could reduce the runtime of my script.
Below is my script as it stands now - this works but as mentioned above it looks up every name on the list in my database and takes 5+ minutes to run.
function datesFASigned() {
var data4RUSS = SpreadsheetApp.getActiveSpreadsheet(); // Set variable for Google Sheet
var shDates = data4RUSS.getSheetByName("Live to RUSS"); //Set variable for Franchise Data
var listLength = shDates.getRange("J4").getValue(); // Set variable for length of FDD list
let listRange = shDates.getSheetValues(4,5,listLength,3); // Set range for Can Sign FA List
var toRUSS = SpreadsheetApp.openById("1H--DhiSVjDnhVV8xYCD-H1QJOrTcML33GG05nzrAXN0");
var dataEntry = toRUSS.getSheetByName("Data Entry"); //Data Entry tab on RUSS
for (var a = 5; a <= listLength+4; a++) //formula to advance through class roster
{
var PPAD = shDates.getRange(a,9).getValue(); //Set variable for Emp roster
console.log(PPAD);
var values = dataEntry.getDataRange().getValues(); //getting the entire values from Emp Data range and assigning it to values variable
for (var i = 0; i < values.length; i++) // formula to search Emp Data for Emp Name in column CP
{
var rowValue = values[i]; // declaring the data row as a variable
//checking the first value of the record is equal to search item
if (rowValue[0] == PPAD) {
var iRow = i+1; //identify the row number
console.log(iRow)
dataEntry.getRange(iRow, 43).setValue(shDates.getRange(a,12).getValue()); //Date ppAD Signed FA
valuesFound=true;
}
}
}
}
try:
function datesFASigned() {
var data4RUSS = SpreadsheetApp.getActiveSpreadsheet(); // Set variable for Google Sheet
var shDates = data4RUSS.getSheetByName("Live to RUSS"); // Set variable for Franchise Data
var listLength = shDates.getRange("J4").getValue(); // Set variable for length of FDD list
let listRange = shDates.getSheetValues(4, 5, listLength, 3); // Set range for Can Sign FA List
var toRUSS = SpreadsheetApp.openById("1H--DhiSVjDnhVV8xYCD-H1QJOrTcML33GG05nzrAXN0");
var dataEntry = toRUSS.getSheetByName("Data Entry"); // Data Entry tab on RUSS
for (var a = 5; a <= listLength + 4; a++) { // Formula to advance through class roster
var PPAD = shDates.getRange(a, 9).getValue(); // Set variable for Emp roster
var dateInG = shDates.getRange(a, 7).getValue(); // Get the value in the G column
// Skip the row if the G column is empty
if (!dateInG) {
continue;
}
console.log(PPAD);
var values = dataEntry.getDataRange().getValues(); // Getting the entire values from Emp Data range and assigning it to values variable
for (var i = 0; i < values.length; i++) { // Formula to search Emp Data for Emp Name in column CP
var rowValue = values[i]; // Declaring the data row as a variable
// Checking the first value of the record is equal to search item
if (rowValue[0] == PPAD) {
var iRow = i + 1; // Identify the row number
console.log(iRow);
dataEntry.getRange(iRow, 43).setValue(shDates.getRange(a, 12).getValue()); // Date ppAD Signed FA
}
}
}
}