สามารถนำ Web App URL ที่ได้จากการ Deploy สคริปต์ Google Apps Script ใน Google Sheet มาใส่ในช่องด้านล่าง เพื่อให้ข้อมูลถูกส่งเข้า Sheet ทันทีที่กด Submit
📄 โค้ด Google Apps Script (Code.gs)
คัดลอกโค้ดด้านล่างไปวางใน Extensions > Apps Script ใน Google Sheet ของท่าน:
function doPost(e) {
var lock = LockService.getScriptLock();
lock.tryLock(10000);
try {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var data = JSON.parse(e.postData.contents);
var headers = [
"Timestamp", "IRIS Caller", "เลขนิติบุคคล (13 หลัก)", "บริษัท / องค์กร", "อีเมลองค์กร", "เบอร์โทรศัพท์",
"กลุ่มอุตสาหกรรม", "หมวดธุรกิจ", "จำนวนพนักงาน",
"P1.1", "P1.2", "P1.3", "P2.1", "P2.2", "P2.3", "P3.1", "P3.2", "P3.3",
"P4.1", "P4.2", "P4.3", "P5.1", "P5.2", "P5.3", "P6.1", "P6.2", "P6.3",
"P7.1", "P7.2", "P7.3", "P7.4",
"คะแนนรวม (110)", "ร้อยละ (%)", "ระดับวุฒิภาวะ",
"สนใจ L2", "สนใจ L3", "ชื่อผู้ประสานงาน", "อีเมลผู้ประสานงาน", "เบอร์โทรผู้ประสานงาน",
"ยินยอม PDPA", "บันทึกการโทร & Feedback"
];
if (sheet.getLastRow() === 0) {
sheet.appendRow(headers);
sheet.getRange(1, 1, 1, headers.length).setBackground("#16213f").setFontColor("#fff").setFontWeight("bold");
}
var row = [
data.timestamp, data.caller, "'" + data.taxId, data.company, data.email, data.phone,
data.industry, data.sector, data.companySize,
data.answers["p1_q1"], data.answers["p1_q2"], data.answers["p1_q3"],
data.answers["p2_q1"], data.answers["p2_q2"], data.answers["p2_q3"],
data.answers["p3_q1"], data.answers["p3_q2"], data.answers["p3_q3"],
data.answers["p4_q1"], data.answers["p4_q2"], data.answers["p4_q3"],
data.answers["p5_q1"], data.answers["p5_q2"], data.answers["p5_q3"],
data.answers["p6_q1"], data.answers["p6_q2"], data.answers["p6_q3"],
data.answers["p7_q1"], data.answers["p7_q2"], data.answers["p7_q3"], data.answers["p7_q4"],
data.totalScore, data.scorePercent, data.maturityLevel,
data.interestedL2 ? "สนใจ" : "ไม่สนใจ", data.interestedL3 ? "สนใจ" : "ไม่สนใจ",
data.coordinatorName || "", data.coordinatorEmail || "", data.coordinatorPhone || "",
data.pdpaConsent ? "ยินยอม" : "", data.callNotes || ""
];
sheet.appendRow(row);
return ContentService.createTextOutput(JSON.stringify({ status: "success" })).setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService.createTextOutput(JSON.stringify({ status: "error", message: err.toString() })).setMimeType(ContentService.MimeType.JSON);
} finally {
lock.releaseLock();
}
}