google docs - Script not changing data on template -


i have been trying create script email me report when form completed. sending email , pdf properly, not replacing key data data form. doing wrong?

code.gs

var doctemplate = "19vff3mzo9gbd2xywmrhlbfmnvzuxc4tdf44bcqr9sfy"; var docname = "test form2pdf";  function onformsubmit(e) {   var email_address = "email@goeshere.net";   var field1 = e.values[1];   var field2 = e.values[2];   var field3 = e.values[3];   var field4 = e.values[4];   var field5 = e.values[5];   var field6 = e.values[6];   var field7 = e.values[7];    // document template, copy new temp doc, , save doc’s id                           var copyid = docslist.getfilebyid(doctemplate)     .makecopy(docname + ' ' + field1)     .getid();    // open temporary document   var copydoc = documentapp.openbyid(copyid);    // document’s body section   var copybody = copydoc.getactivesection();   copybody.replacetext('keyfield1', field1);   copybody.replacetext('keyfield2', field2);   copybody.replacetext('keyfield3', field3);   copybody.replacetext('keyfield4', field4);   copybody.replacetext('keyfield5', field5);   copybody.replacetext('keyfield6', field6);   copybody.replacetext('keyfield7', field7);   // save , close temporary document   copydoc.saveandclose();    // convert temporary document pdf   var pdf = docslist.getfilebyid(copyid).getas("application/pdf");    // attach pdf , send email   var subject = "test form report";   var body = "here test form " + field1 + "";   mailapp.sendemail(email_address, subject, body, {     htmlbody: body,     attachments: pdf   });    // delete temp file   docslist.getfilebyid(copyid).settrashed(true); } 

doctemplate

process: responsible resource fill out form , send appropriate stakeholder approval prior making change network/server environment.  1. description: keyfield1  2. systems impacted: keyfield2  3. start date/time/duration: keyfield3  4. benefits: keyfield4  5. responsible resources/contact info: keyfield5  6. business impact: [how affect business?]: keyfield6  7. testing: [what test plan]: keyfield7 

the problem keyfields in template document have different capitalization in code - therefore not found replacetext() method.

the advice in google apps script document not accessible replacetext() applies here well; keys better if included odd punctuation. , they'd less error-prone (and more obvious) if in caps, e.g. %keyfield1%. , better meaningful names, e.g. %description%, %systems_impacted%, etc.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -