Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
How do I make the JavaScript code using the HtmlService class output as a google form in email when a button is clicked instead of raw html?

Here is the code:

const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName("StudentReport_all");
const range = ws.getRange(4,1,ws.getLastRow(),ws.getLastColumn());
const data = range.getValues();

var form = FormApp.openById("154QspMd1P4RmTRDnOQHL06dU-KvL8FPU53wHYcar09U");
  //form.setRequireLogin(true);

var formUrl = form.getPublishedUrl();
var title = form.getTitle();
var descriptionText = form.getDescription();

function sendForm() {
  
  var subject = "Response Needed: " + form.getTitle()
  var response = UrlFetchApp.fetch(formUrl);
  var template = HtmlService.createHtmlOutput(response);
  
  //var htmlBody = HtmlService.createHtmlOutputFromFile("teacherEmail").getContent();
var htmlBody = template.getContent();
//HtmlService


  var p1Email = data[9][3];
  var p2Email = data[10][3]
  var p3Email = data[11][3]
  var p4Email = data[12][3]
  var p5Email = data[13][3]
  var p6Email = data[14][3]


GmailApp.sendEmail(
      [p1Email],
      subject,
      htmlBody
  )
 return htmlBody
  Logger.log(htmlBody);
}

When I click the button in Google Sheets, an email should send to the entered emails and the google form template should show up in the email. But when I click the button, instead of the google form template, the raw html shows up. How do I fix this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!