How to consider empty answers in Google form using Google Apps Script? -
i made google form , script sends mail content of form.
there 3 fields: a, b, c not mandatory. example: if enter 1, 5, , 8 script writing:
a=1, b=5, c=8
the problem if b not given value (1 , 3 c), output:
a=1, b=3, c=
there shift of values! can ?
function sendresponses() { var form = formapp.getactiveform(); var responses = form.getresponses(); var lastrow = responses.length - 1; var itemresponses = responses[lastrow].getitemresponses(); var total = "a=" + itemresponses[0].getresponse() + ", b=" + itemresponses[1].getresponse() + ", c=" + itemresponses[2].getresponse(), }
thank you, frédéric
when use code, it's giving me results want:
function sendresponses(e) { var thisresponse = e.response; logger.log('thisresponse: ' + thisresponse); var itemresponses = thisresponse.getitemresponses(); logger.log('itemresponses: ' + itemresponses); var total = "a=" + itemresponses[0].getresponse() + ", b=" + itemresponses[1].getresponse() + ", c=" + itemresponses[2].getresponse(); logger.log('total: ' + total); }
note don't need form responses. code retrieves responses, past , present. can current response. note variable e argument in sendresponses function:
function sendresponses(e) {
i created form 3 text fields, , did not put in second field. log prints this:
[14-09-10 16:25:44:265 edt] thisresponse: formresponse
[14-09-10 16:25:44:267 edt] itemresponses: itemresponse,itemresponse,itemresponse
[14-09-10 16:25:44:268 edt] total: a=1, b=, c=c
the function triggered when form submitted:
Comments
Post a Comment