Your sendtoContacts ()
function is using ss.getActiveRange().getRowIndex();
to determine which row to use but nowhere in your script you set any row to active so you keep using the same data all the way through the main loop in MakeAllContacts()
.
There are 2 possible solutions :
- use
activate()
in theMakeAllContacts()
function loop so that the active row changes for each iteration (ss.getRange(row,1).activate()
) - use a rowIndex parameter in the
sendtoContacts ()
function like below :
function MakeAllContacts() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var ss = source.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 100; // Number of rows to process
for (row = 2; row < numRows; row++){
sendtoContacts(row);
}
}
and then change the function sendtoContacts ()
function like this:
function sendtoContacts (row) { // row as parameter
var source = SpreadsheetApp.getActiveSpreadsheet();
var ss = source.getActiveSheet();
...
That said, this approach is not very efficient since each data is read in the spreadsheet using a single getRange/getValue which is particularly slow... please read the best practice to get inspiration on how to handle your data more efficiently using a single getValues()
and iterate the array content instead.