i've got script works (i outputs expect) gives me cannot call method "split of undefined (line 16). if comment out line 16, error moves line 17 etc.
function emf() var ss = spreadsheetapp.openbyid('####').getsheetbyname('emf'); { var label = gmailapp.getuserlabelbyname("tkh_emf"); var threads = label.getthreads(); (var i=0; i<threads.length; i++) { var messages = threads[i].getmessages(); (var j=0; j<messages.length; j++) { var fullname = messages[j].getplainbody().split("name*: ")[1].split("\n")[0]; // used gmap column title var fname = fullname.split(" ")[0]; var lname = fullname.split(" ")[1]; var email = messages[j].getplainbody().split("email*: ")[1].split("\n")[0]; var phone = messages[j].getplainbody().split("phone*: ")[1].split("\n")[0]; var addr = messages[j].getplainbody().split("street address*: ")[1].split("\n")[0]; var city = messages[j].getplainbody().split("city*: ")[1].split("\n")[0]; var find = messages[j].getplainbody().split("hear us?*: ")[1].split("\n")[0]; var referrer = messages[j].getplainbody().split("referrer name: ")[1].split("\n")[0]; var photo = messages[j].getplainbody().split("(max size 2mb): ")[1].split("\n")[0]; var site = messages[j].getsubject().split("contact ")[1].split("from")[0]; var date = messages[j].getdate(); var work = messages[j].getplainbody().split("brief description of work requested*: ")[1].split("visitor ip: ")[0]; var ip = messages[j].getplainbody().split("visitor ip: ")[1].split("follow @emfteam")[0]; // var rownum = lastrow + 1; ss.appendrow([fullname, fname, lname, date, work, photo, email, phone, addr, city, find, referrer, site, ip,'pending','pending']); } // threads[i].removelabel(label); } }
here's format of messages scraping ...
what missing? why giving me error?
you can skip messages cause error try
, catch
. here example
function emf() { var ss = spreadsheetapp.openbyid('####').getsheetbyname('emf'); var label = gmailapp.getuserlabelbyname("tkh_emf"); var threads = label.getthreads(); (var i=0; i<threads.length; i++) { var messages = threads[i].getmessages(); (var j=0; j<messages.length; j++) { try { var plainbody = messages[j].getplainbody(); var fullname = plainbody.split("name*: ")[1].split("\n")[0]; // used gmap column title var fname = fullname.split(" ")[0]; var lname = fullname.split(" ")[1]; var email = plainbody.split("email*: ")[1].split("\n")[0]; var phone = plainbody.split("phone*: ")[1].split("\n")[0]; var addr = plainbody.split("street address*: ")[1].split("\n")[0]; var city = plainbody.split("city*: ")[1].split("\n")[0]; var find = plainbody.split("hear us?*: ")[1].split("\n")[0]; var referrer = plainbody.split("referrer name: ")[1].split("\n")[0]; var photo = plainbody.split("(max size 2mb): ")[1].split("\n")[0]; var site = messages[j].getsubject().split("contact ")[1].split("from")[0]; var date = messages[j].getdate(); var work = plainbody.split("brief description of work requested*: ")[1].split("visitor ip: ")[0]; var ip = plainbody.split("visitor ip: ")[1].split("follow @emfteam")[0]; ss.appendrow([fullname, fname, lname, date, work, photo, email, phone, addr, city, find, referrer, site, ip,'pending','pending']); } catch(e) { } } } }
Comments
Post a Comment