Exceeded maximum execution time in Google App Script with Contacts API -
i creating script responsible of generating report containing info set of groups , contacts in google app script.
if select few groups, goes ok if select several (20 or more), scripts launches "exceeded maximum execution time" error.
how reduce script time execution?
thanks!
my (reduced) script
var allcontactsinfo = [] /ii. each group for(var = 0 ; < numberofgroups ; i++) { var selected = eventinfo.parameter["group"+i] var contactinfo = [] //iii. if has been selected user if(selected) { //iv. contact group , contacts var contactgroup = contactsapp.getcontactgroupbyid(eventinfo.parameter["group_"+i+"_id"]) var contacts = contactgroup.getcontacts() //iv. iterate on each group contact (var j=0; j < contacts.length; j++) { var contact = contacts[j]; contactinfo.push(contact.getgivenname()) contactinfo.push(contact.getfamilyname()) var groups = contact.getcontactgroups() var groupsasarray = [] (var k = 0 ; k < groups.length; k++) { groupsasarray.push(groups[k].getname()) } contactinfo.push(groupsasarray.sort().join()) //v. add contact array allcontactsinfo.push(contactinfo) } } ... ... //vi. fill spreadsheet array built within loop sheet.getrange(1, 1, allcontactsinfo.length, headers.length).setvalues(allcontactsinfo);
update
after tests, have found bottleneck produced returning user's groups (via contact.getcontactgroups()).
returning name, surnames, emails, addresses , phones works ok if include user's groups too, timeout exception appears...
update 2
here working solution, hope helps :)
https://github.com/antacerod/google-app-script-6-minutes-limitation
finally have found post.
it shows nice workaround related checkbox setvalue method implementation , second parameter (sets whether checkbox should checked , optionally fires event if value changes result of call)
in case, works charm!
Comments
Post a Comment