TypeError: Cannot read property 'value' of undefined (line 3, file "Code"). I have a trigger for on form submit and yet it still has an error
Asked Answered
M

1

0
  1. Function has a trigger for on form submit

  2. having issues with this very first line. Its supposed to grab data from excel sheet to auto-populate into a copy of template

    function autofillGoogleDocFromForm(e) {
      var timeStamp = e.value[0];
      var lastname = e.value[1];
      var firstname = e.value[2];
      var rank = e.value[3];
      var gender = e.value[4];
      var last4ssn = e.value[5];
      var age = e.value[6];
      var phonenumber = e.value[7];
      var email = e.value[8];
      var MOSAOC = e.value[9];
      var BN = e.value[10];
      var BTRY = e.value[11];
      var platoonsection = e.value[12];
      var region = e.value[13];
      var laterality = e.value[14];
      var painduration = e.value[15];
      var DOI = e.value[16];
      var MOI = e.value[17];
      var HPI = e.value[18];
      var stability = e.value[19];
      var variability = e.value[20];
      var aggs = e.value[21];
      var eases = e.value[22];
      var prevtx = e.value[23];
      var imaging = e.value[24];
      var painc = e.value[25];
      var painl = e.value[26];
      var painh = e.value[27];
      var profile = e.value[28];
      var medhx = e.value[29];
      var surg = e.value[30];
      var famhx = e.value[31];
      var tobaccou = e.value[32];
      var tobaccof = e.value[33];
      var tobaccoc = e.value[34];
      var meds = e.value[35];
      var legweak = e.value[36];
      var nt = e.value[37];
      var wtchange = e.value[38];
      var fcns = e.value[39];
      var appetite = e.value[40];
      var bbchange = e.value[41];
      var ddh = e.value[42];
      var sihi = e.value[43];
      var bhchap = e.value[44];
      var goals = e.value[45];
      var important = e.value[46];
      var confident = e.value[47];
      var C19contact = e.value[48];
      var C19travel = e.value[49];
      var C19sx = e.value[50];
      var templateFile = DriveApp.getFileById("");
      var templateResponseFolder = DriveApp.getFolderById("");
      var copy = templateFile.makeCopy(lastname + ',' + firstname, templateResponseFolder);
      var doc = DocumentApp.openById(copy.getId());
      var body = doc.getBody();
      body.replaceText("{{date}}", timeStamp);
      body.replaceText("{{last}}", lastname);
      body.replaceText("{{first}}", firstname);
      body.replaceText("{{rank}}", rank);
      body.replaceText("{{gender}}", gender);
      body.replaceText("{{id}}", last4ssn);
      body.replaceText("{{age}}", age);
      body.replaceText("{{phone}}", phonenumber);
      body.replaceText("{{email}}", email);
      body.replaceText("{{mos}}", MOSAOC);
      body.replaceText("{{bn}}", BN);
      body.replaceText("{{btry}}", BTRY);
      body.replaceText("{{plt}}", platoonsection);
      body.replaceText("{{region}}", region);
      body.replaceText("{{laterality", laterality);
      body.replaceText("{{doi}}", DOI);
      body.replaceText("{{moi}}", MOI);
      body.replaceText("{{hpi}}", HPI);
      body.replaceText("{{stability}}", stability);
      body.replaceText("{{variability}}", variability);
      body.replaceText("{{aggs}}", aggs);
      body.replaceText("{{eases}}", eases);
      body.replaceText("{{prevtx}}", prevtx);
      body.replaceText("{{imaging}}", imaging);
      body.replaceText("{{painc}}", painc);
      body.replaceText("{{painl}}", painl);
      body.replaceText("{{painh}}", painh);
      body.replaceText("{{profile}}", profile);
      body.replaceText("{{medhx}}", medhx);
      body.replaceText("{{surg}}", surg);
      body.replaceText("{{famhx}}", famhx);
      body.replaceText("{{tobaccou}}", tobaccou);
      body.replaceText("{{tobaccof}}", tobaccof);
      body.replaceText("{{tobaccoc}}", tobaccoc);
      body.replaceText("{{meds}}", meds);
      body.replaceText("{{legweak}}", legweak);
      body.replaceText("{{nt}}", nt);
      body.replaceText("{{wtchange}}", wtchange);
      body.replaceText("{{fcns}}", fcns);
      body.replaceText("{{appetite}}", appetite);
      body.replaceText("{{bbchange}}", bbchange);
      body.replaceText("{{ddh}}", ddh);
      body.replaceText("{{sihi}}", sihi);
      body.replaceText("{{bhchap}}", bhchap);
      body.replaceText("{{goals}}", goals);
      body.replaceText("{{important}}", important);
      body.replaceText("{{confident}}", confident);
      body.replaceText("{{c19travel}}", C19travel);
      body.replaceText("{{c19sx}}", C19sx);
      body.replaceText("{{c19contact}}", C19contact);
      doc.saveAndClose();
    }
Mycosis answered 18/10, 2022 at 0:45 Comment(3)
e.value is actually e.valuesLabbe
Apologies I am new and trying to fix it for work. What is difference between e.value and e.values?Mycosis
just an s but unfortunately spelling counts in codingLabbe
L
1

Try this:

function autofillGoogleDocFromForm(e) {
  var timeStamp = e.values[0];
  var lastname = e.values[1];
  var firstname = e.values[2];
  var rank = e.values[3];
  var gender = e.values[4];
  var last4ssn = e.values[5];
  var age = e.values[6];
  var phonenumber = e.values[7];
  var email = e.values[8];
  var MOSAOC = e.values[9];
  var BN = e.values[10];
  var BTRY = e.values[11];
  var platoonsection = e.values[12];
  var region = e.values[13];
  var laterality = e.values[14];
  var painduration = e.values[15];
  var DOI = e.values[16];
  var MOI = e.values[17];
  var HPI = e.values[18];
  var stability = e.values[19];
  var variability = e.values[20];
  var aggs = e.values[21];
  var eases = e.values[22];
  var prevtx = e.values[23];
  var imaging = e.values[24];
  var painc = e.values[25];
  var painl = e.values[26];
  var painh = e.values[27];
  var profile = e.values[28];
  var medhx = e.values[29];
  var surg = e.values[30];
  var famhx = e.values[31];
  var tobaccou = e.values[32];
  var tobaccof = e.values[33];
  var tobaccoc = e.values[34];
  var meds = e.values[35];
  var legweak = e.values[36];
  var nt = e.values[37];
  var wtchange = e.values[38];
  var fcns = e.values[39];
  var appetite = e.values[40];
  var bbchange = e.values[41];
  var ddh = e.values[42];
  var sihi = e.values[43];
  var bhchap = e.values[44];
  var goals = e.values[45];
  var important = e.values[46];
  var confident = e.values[47];
  var C19contact = e.values[48];
  var C19travel = e.values[49];
  var C19sx = e.values[50];
  var templateFile = DriveApp.getFileById("");
  var templateResponseFolder = DriveApp.getFolderById("");
  var copy = templateFile.makeCopy(lastname + ',' + firstname, templateResponseFolder);
  var doc = DocumentApp.openById(copy.getId());
  var body = doc.getBody();
  body.replaceText("{{date}}", timeStamp);
  body.replaceText("{{last}}", lastname);
  body.replaceText("{{first}}", firstname);
  body.replaceText("{{rank}}", rank);
  body.replaceText("{{gender}}", gender);
  body.replaceText("{{id}}", last4ssn);
  body.replaceText("{{age}}", age);
  body.replaceText("{{phone}}", phonenumber);
  body.replaceText("{{email}}", email);
  body.replaceText("{{mos}}", MOSAOC);
  body.replaceText("{{bn}}", BN);
  body.replaceText("{{btry}}", BTRY);
  body.replaceText("{{plt}}", platoonsection);
  body.replaceText("{{region}}", region);
  body.replaceText("{{laterality", laterality);
  body.replaceText("{{doi}}", DOI);
  body.replaceText("{{moi}}", MOI);
  body.replaceText("{{hpi}}", HPI);
  body.replaceText("{{stability}}", stability);
  body.replaceText("{{variability}}", variability);
  body.replaceText("{{aggs}}", aggs);
  body.replaceText("{{eases}}", eases);
  body.replaceText("{{prevtx}}", prevtx);
  body.replaceText("{{imaging}}", imaging);
  body.replaceText("{{painc}}", painc);
  body.replaceText("{{painl}}", painl);
  body.replaceText("{{painh}}", painh);
  body.replaceText("{{profile}}", profile);
  body.replaceText("{{medhx}}", medhx);
  body.replaceText("{{surg}}", surg);
  body.replaceText("{{famhx}}", famhx);
  body.replaceText("{{tobaccou}}", tobaccou);
  body.replaceText("{{tobaccof}}", tobaccof);
  body.replaceText("{{tobaccoc}}", tobaccoc);
  body.replaceText("{{meds}}", meds);
  body.replaceText("{{legweak}}", legweak);
  body.replaceText("{{nt}}", nt);
  body.replaceText("{{wtchange}}", wtchange);
  body.replaceText("{{fcns}}", fcns);
  body.replaceText("{{appetite}}", appetite);
  body.replaceText("{{bbchange}}", bbchange);
  body.replaceText("{{ddh}}", ddh);
  body.replaceText("{{sihi}}", sihi);
  body.replaceText("{{bhchap}}", bhchap);
  body.replaceText("{{goals}}", goals);
  body.replaceText("{{important}}", important);
  body.replaceText("{{confident}}", confident);
  body.replaceText("{{c19travel}}", C19travel);
  body.replaceText("{{c19sx}}", C19sx);
  body.replaceText("{{c19contact}}", C19contact);
  doc.saveAndClose();
}

on Form Submit

Labbe answered 18/10, 2022 at 1:1 Comment(1)
Cooper you are beautiful thank you so much it worked.Mycosis

© 2022 - 2024 — McMap. All rights reserved.