I've assigned a variable:Serial in Google apps script (code.gs) and want to fetch the value in (success.html) page after form submission. Here is my code.gs
function doPost(e) {
const folderId = "root"; // Or Folder ID which is used for putting the file instead of "root", if you need.
const sheetId = "<sheetid>"; // Replace with your sheet ID
const sheet = SpreadsheetApp.openById(sheetId).getSheetByName("sheet1");
const name = e.parameter.name;
const email = e.parameter.email;
const file = e.postData.contents ? Utilities.newBlob(JSON.parse(e.postData.contents), e.parameter.mimeType, e.parameter.filename) : null;
var currentDate = new Date();
var month = currentDate.toLocaleString('default', { month: 'short' });
var year = currentDate.getFullYear().toString().substr(-2);
var serialNumber = 'D' + month + year + pad(sheet.getLastRow() + 1, 4);
function pad(num, length) {
var str = num.toString();
while (str.length < length) {
str = '0' + str;
}
return str;
}
if (file) {
const uploadedFile = DriveApp.getFolderById(folderId).createFile(file);
const responseObj = { filename: uploadedFile.getName(), fileId: uploadedFile.getId(), fileUrl: uploadedFile.getUrl(), name: name, email: email };
const sheet = SpreadsheetApp.openById(sheetId).getSheetByName("sheet1"); // Replace "Sheet1" with the name of your sheet
sheet.appendRow([serialNumber, name, email, uploadedFile.getUrl()]);
//return ContentService.createTextOutput("Form Submitted Successfully");
return ContentService.createTextOutput(JSON.stringify(responseObj)).setMimeType(ContentService.MimeType.JSON);
} else {
const sheet = SpreadsheetApp.openById(sheetId).getSheetByName("sheet1"); // Replace "Sheet1" with the name of your sheet
sheet.appendRow([serialNumber, name, email, ""]); // Replace "" with the default values for other columns if needed
//return ContentService.createTextOutput("Form Submitted Successfully");
return ContentService.createTextOutput(JSON.stringify({ name: name, email: email })).setMimeType(ContentService.MimeType.JSON);
}
}
function doGet() {
return HtmlService.createHtmlOutputFromFile("success.html").setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
And here is my success.html code
<!DOCTYPE html>
<html>
<head>
<title>Thank You!</title>
</head>
<body>
<h1>Thank you for submitting the form!</h1>
<h2><?= serialNumber ?></h2>
</body>
</html>
Need value of serial variable in success.html i.e, assigned in code.js. note: this question related to my last question refer Here