I have over 500 contacts in Google. I am wanting to list all the contacts that are associated with a particular company into a sheet. When I run the following script, I receive a timeout error.
function Step2_Contacts(x){
//Adding Contact information
var x = "Company Name";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(x);
var contacts, outputTitle = [], outputEmail = [], outputPhone = [], outputAddress = [], outputName = [], outputNotes = [], cStart = ContactsApp.getContacts();
for(var i = 0, iLen = cStart.length; i < iLen; i++) {
var fullname = cStart[i].getFullName();
contacts = ContactsApp.getContactsByName(fullname);
for (y in contacts) {
var company = contacts[y].getCompanies();
var email = contacts[y].getEmails(ContactsApp.Field.WORK_EMAIL);
var phone = contacts[y].getPhones();
var addr = contacts[y].getAddresses(ContactsApp.Field.HOME_ADDRESS);
var notes = contacts[y].getNotes();
for (var z in state){
if (company[y].getCompanyName() == x){
outputTitle.push([company[z].getJobTitle()]);
outputEmail.push([email[z].getAddress()]);
outputPhone.push([phone[z].getPhoneNumber()]);
outputAddress.push([addr[z].getAddress()]);
outputName.push([fullname]);
outputNotes.push([notes]);
};
};
};
};
//Adding in Contact Information
sheet.getRange(7, 4, outputName.length, 1).setValues(outputName);
sheet.getRange(7, 5, outputTitle.length, 1).setValues(outputTitle);
sheet.getRange(7, 6, outputEmail.length, 1).setValues(outputEmail);
sheet.getRange(7, 7, outputPhone.length, 1).setValues(outputPhone);
sheet.getRange(7, 8, outputAddress.length, 1).setValues(outputAddress);
sheet.getRange(7, 9, outputNotes.length, 1).setValues(outputNotes);
};
What I think happens is that every loop the arrays will add another dimension to all the arrays listed within the loop.
cStart
?state
?