javascript - google apps scripts check contact exist, then update from sheet -


not sure i've gone wrong. trying check if contact exists before creating it. once done, adding timestamp row.

var dateformat = utilities.formatdate(new date(), "gmt-2", "yyyy-mm-dd' 'hh:mm:ss"); var tkhcontacts = spreadsheetapp.openbyid('###').getsheetbyname('contacts');  function update(){ // -- update contacts -- runs on master spreadsheet tkh contacts emf (contact)   // importrefresh(); don't need   var range = tkhcontacts.getlastrow();   var updatecol = tkhlastupdatedcol();   var data = tkhcontacts.getrange(updatecol+"1:"+updatecol+range).getvalues();   for(var n=range;n>1;n--)   {       var lastupdate = tkhcontacts.getrange(updatecol+n).getvalue(); // last update col        var email = tkhcontacts.getrange("h"+n).getvalue();       var fname = tkhcontacts.getrange("c"+n).getvalue();       var lname = tkhcontacts.getrange("d"+n).getvalue();       var city = tkhcontacts.getrange("k"+n).getvalue().trim();       var street = tkhcontacts.getrange("j"+n).getvalue().trim();       var zip = tkhcontacts.getrange("l"+n).getvalue();       var phone = tkhcontacts.getrange("i"+n).getvalue();       var date = tkhcontacts.getrange("e"+n).getvalue();       var work = tkhcontacts.getrange("f"+n).getvalue();       var photo = tkhcontacts.getrange("g"+n).getvalue();       var site = tkhcontacts.getrange("o"+n).getvalue();       var find = tkhcontacts.getrange("m"+n).getvalue();       var referrer = tkhcontacts.getrange("n"+n).getvalue();       var tkhnotes = tkhcontacts.getrange("a"+n).getvalue();       var ip = tkhcontacts.getrange("p"+n).getvalue();       var email2 = tkhcontacts.getrange("q"+n).getvalue();       var phone2 = tkhcontacts.getrange("r"+n).getvalue();        if(lastupdate == 'pending') {         var contact = contactsapp.getcontactsbyname(fname + " " + lname);         if(contact){continue}         else{           var contact = contactsapp.createcontact(fname, lname, email);           var group = contactsapp.getcontactgroup('emf');           group.addcontact(contact);           var contacts = contactsapp.getcontactsbyname(fname + " " + lname); }      }     (var in contacts){contacts[i].setnotes(date + "\n\n" + work + photo + find + '\n' + referrer + '\n' + ip + '\n' + site + "\n\n" + tkhnotes);}     tkhcontacts.getrange(updatecol+n).setvalue(dateformat);   } 

should straightforward i'm having difficulty.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -