Dear all.
I need an help if it's possible.
I've a function that write some contact in Google Contact.
Sometimes the funcion return this error:
{ "error": { "code": 503, "message": "The service is currently unavailable.", "status": "UNAVAILABLE" }
I read that to prevent this type of error is reccomended to use Exponential Backoff.
I'm trying ....without success.
can I ask for your help?
I execute exec_1 function.
function exec_1() {
var partial_import = call(createContact(2,19));
};
//Exponential Backoff
function call(func) {
for (var n=0; n<6; n++) {
try {
return func();
} catch(e) {
if (n == 5) {
throw e;
}
Utilities.sleep((Math.pow(2,n)*1000) + (Math.round(Math.random() * 1000)));
}
}
}
function createContact(startRow,numRows) {
var GroupName = "SharedContact"; //Name of contact label
var sheet = SpreadsheetApp.getActiveSheet();
var group = ContactsApp.getContactGroup(GroupName);
// Fetch the range
var dataRange = sheet.getRange(startRow, 1, numRows, 8);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var firstName = row[0];
// Se la riga ha valore FirstName vuoto esce dallo script
if (firstName == 0) return;
var lastName = row[1];
var emailAddress = row[2];
var phone = row[3];
var company = row[4];
var notes = row[5];
var address = row[6];
var DeleteContact = row[7];
// Create contact in Google Contacts
if (DeleteContact != "Yes") {
var contact = ContactsApp.createContact(firstName, lastName, emailAddress);
// Add values to new contact
contact.addCompany(company, "");
contact.addPhone(ContactsApp.Field.WORK_PHONE, phone);
contact.setNotes(notes);
contact.addAddress(address, address);
contact.addToGroup(group);
};
};
};
The error is
TypeError: func is not a function, is undefined.
The error is in row 7 of function call---> throw e;)
Could some good soul help me?
Thank you all
Andrea