-
-
Save miftahafina/8316958c94f964753e0d91cce3122d19 to your computer and use it in GitHub Desktop.
function doPost(e) { | |
// Buka sheet | |
let sheetUrl = "YOUR_SHEET_URL"; | |
let file = SpreadsheetApp.openByUrl(sheetUrl); | |
let sheet = file.getSheetByName("Sheet1"); | |
// Rapikan data | |
let req = JSON.stringify(e).replace(/\\/g, "").replace("}\"", "}").replace("\"{", "{"); | |
let reqJson = JSON.parse(req); | |
let senderMessage = JSON.stringify(reqJson["postData"]["contents"]["senderMessage"]); | |
// Mengurai isi pesan | |
let parsedMessage = senderMessage.split("#"); | |
// ['"daftar', 'afin', '17/08/1945', 'Indonesia'] | |
let nama = parsedMessage[1].trim(); | |
let tanggalLahir = parsedMessage[2].trim(); | |
let alamat = parsedMessage[3].trim().slice(0, -1); | |
// Membuat ID | |
let row = sheet.getLastRow() + 1; | |
let prefixIdPendaftar = 220000; | |
let idPendaftar = `A-${prefixIdPendaftar + row - 1}`; | |
// Insert data | |
sheet.getRange(`A${row}`).setValue(idPendaftar); | |
sheet.getRange(`B${row}`).setValue(nama); | |
sheet.getRange(`C${row}`).setValue(tanggalLahir); | |
sheet.getRange(`D${row}`).setValue(alamat); | |
// Respon | |
let response = { | |
data: [ | |
{ | |
message: `Terima kasih, ananda ${nama} berhasil terdaftar dengan ID ${idPendaftar}.` | |
} | |
] | |
}; | |
return ContentService.createTextOutput(JSON.stringify(response)); | |
} |
Trimakasih Atas Scriptnya berjalan dengan baik
Mau tanya gan
Scriptnya sedikit saya rubah agar format Pengiriman bisa seperti ini ;
Nama :
NIS :
Kelas :
Namun Jadi terkendala ketika ada huruf "n" maka tidak di respon, mohon petunjuknya
Trimakasih
Berikut script hasil modifnya
function doPost(e) {
// Buka sheet
let sheetUrl = "https://docs.google.com/spreadsheets/d/1fZA6EVegx6cV5NZlc9WZqKgBTZZX8zMQpiRAjPxdvDs/edit?gid=0#gid=0";
let file = SpreadsheetApp.openByUrl(sheetUrl);
let sheet = file.getSheetByName("Sheet1");
// Rapikan data
let req = JSON.stringify(e).replace(/\/g, "").replace("}"", "}").replace(""{", "{");
let reqJson = JSON.parse(req);
let senderMessage = JSON.stringify(reqJson["postData"]["contents"]["senderMessage"]);
// Mengurai isi pesan
let parsedMessage = senderMessage.split("n");
// ['"daftar', 'afin', '17/08/1945', 'Indonesia']
let nis = parsedMessage[1].split(":")[1].trim();
let nama = parsedMessage[2].split(":")[1].trim();
let email = parsedMessage[3].split(":")[1].trim();
let status = parsedMessage[4].split(":")[1].trim().slice(0, -1);
// Membuat ID
let row = sheet.getLastRow() + 1;
let prefixIdPendaftar = 300;
let idPendaftar = MDQ${prefixIdPendaftar + row - 1}
;
let pass = 4${prefixIdPendaftar + row +111}
;
// Insert data
sheet.getRange(A${row}
).setValue(nis);
sheet.getRange(B${row}
).setValue(nama);
sheet.getRange(C${row}
).setValue(email);
sheet.getRange(D${row}
).setValue(idPendaftar);
sheet.getRange(E${row}
).setValue(pass);
sheet.getRange(F${row}
).setValue(status);
// Respon
let response = {
data: [
{
message: Terima kasih, Bapak/Ibu ${nama}, Anda berhasil terdaftar pada System Kami, dengan : *Username* ${idPendaftar} dan *Password* ${pass}.
}
]
};
return ContentService.createTextOutput(JSON.stringify(response));
}
Ini hasil modif
Error
TypeError: Cannot read properties of undefined (reading 'replace')
doPost @ Kode.gs:8