SHARE
TWEET

Untitled

a guest Jun 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function objectifyForm() {
  2.   //Makes the form info into an object
  3.   var myform = FormApp.getActiveForm();
  4.   var formResponses = myform.getResponses()
  5.   var currentResponse = formResponses[formResponses.length-1];
  6.   var responseArray = currentResponse.getItemResponses()
  7.   var form = {};
  8.   form.user = currentResponse.getRespondentEmail(); //requires collect email addresses to be turned on or is undefined.
  9.   form.timestamp = currentResponse.getTimestamp();
  10.   form.formName = myform.getTitle();
  11.   for (var i = 0; i < responseArray.length; i++){
  12.     var response = responseArray[i].getResponse();
  13.     var item = responseArray[i].getItem().getTitle();
  14.     var item = camelize(item);
  15.     form[item] = response;
  16.   }
  17.   return form;
  18. }
  19.  
  20. function camelize(str) {
  21.   str = str.replace(/[.,-/#!$%^&*;:{}=-_`~()@+?><[]+]/g, '')
  22.   return str.replace(/(?:^w|[A-Z]|bw|s+)/g, function(match, index) {
  23.     if (+match === 0) return ""; // or if (/s+/.test(match)) for white spaces
  24.     return index == 0 ? match.toLowerCase() : match.toUpperCase();
  25.   });
  26. }
  27.  
  28.  
  29. //Use with installable trigger
  30. function onSubmittedForm() {
  31.   var form = objectifyForm();
  32.   Logger.log(form);
  33.   //Put Code here
  34.  
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top