google apps script - Calling FormApp within doGet(e) function -
i relatively new scripting, please kind.
i trying create function bound form within google apps, including webapp captures 3 variables (requestnum, approvernum, , status) , obtains various other information formapp (e.g titles, responses, etc).
i receiving - typeerror: cannot call method "getid" of null on line 3 of below code (which bound form).
any guidance in being able call form information within doget function appreciated! thank you.
function doget(e){ var form = formapp.getactiveform(); var formid = form.getid(); var items = form.getitems(); var d = new date(); var formatteddate = utilities.formatdate(d, "gmt+11", "mmm dd yyyy"); var conn = jdbc.getconnection(dburl, user, userpwd); var stmt = conn.preparestatement('insert approvals ' + '(formid, requestnum, approvernum, status, date) values (?, ?, ?, ?, ?)'); stmt.setstring(1, formid); stmt.setstring(2, e.parameter.requestnum); stmt.setstring(3, e.parameter.approvernum); stmt.setstring(4, e.parameter.status); stmt.setstring(5, d); stmt.execute(); var nextapprovernum = e.parameter.approvernum + 1; var answer = e.parameter.status; var requestnum = e.parameter.requestnum; var nextapproveremail = e.parameter.reply; var titles = []; (i=0; i<items.length; i++) { titles.push(items[i].gettitle()); } var responses = []; var formresponses = form.getresponses(); var itemresponses = formresponses[requestnum-1].getitemresponses(); (var j = 0; j < itemresponses.length; j++) { responses.push(itemresponses[j].getresponse()); } ....etc
under right conditions access, code you're having problems works. should review settings you've used publishing web app.
this snippet focuses on issue you've brought up, , works expected:
function doget(e){ // var form = formapp.getactiveform(); // typeerror: cannot call method "getid" of null. var form = formapp.openbyid('17ltbrlmqxggvadlnpc6dgtzf1f2scea1rc9zipbu_uq'); var formid = form.getid(); var items = form.getitems(); return contentservice.createtextoutput("form contains "+items.length+"items."); }
Comments
Post a Comment