Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function afterFormSubmit(e) {
- const info = e.namedValues;
- const pdfFile = createPDF(info);
- const entryRow = e.range.getRow();
- const ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Laporan");
- ws.getRange(entryRow, 1).setValue(pdfFile.getUrl());
- ws.getRange(entryRow, 2).setValue(pdfFile.getName());
- sendEmail(e.namedValues['Email Address'][0], pdfFile, e.namedValues['Tahap Bimtek'][0]);
- }
- function sendEmail(email, pdfFile, tahapan) {
- GmailApp.sendEmail(email, "BIMBINGAN TEKNIS PENYELESAIAN LAPORAN AKHIR DAN TTE BAST TAHUN 2021", "Peserta Bimbingan Penyelesaian Laporan Akhir dan TTE BAST Tahun 2021, " + tahapan, {
- attachments: [pdfFile],
- name: 'Bidang Sarpras Direktorat SMA 2021'
- });
- }
- function createPDF(info) {
- const pdfFolder = DriveApp.getFolderById("1VhhxROSVtUTlC7pQ853e4ciosZe3h4U_");
- const tempFolder = DriveApp.getFolderById("1W_QRvRz2HHxLKA7MDPUWeZzUi86D2g18");
- const templateDoc = DriveApp.getFileById("15BQyFJ-RkcfpvmR_h9t-dfj85Onp2xa95I9eVQpJ0zk");
- const newTempFile = templateDoc.makeCopy(tempFolder);
- const openDoc = DocumentApp.openById(newTempFile.getId());
- const body = openDoc.getBody();
- body.replaceText("{nama}", info['Nama Peserta'][0]);
- body.replaceText("{nip}", info['NIP'][0]);
- body.replaceText("{pangkat}", info['Pangkat/Gol'][0]);
- body.replaceText("{jabatan}", info['Jabatan'][0]);
- body.replaceText("{hp}", info['No. Handphone (Whatsapp)'][0]);
- body.replaceText("{email}", info['Email Address'][0]);
- body.replaceText("{nama_instansi}", info['Nama Instansi'][0]);
- body.replaceText("{npsn}", info['NPSN'][0]);
- body.replaceText("{alamat}", info['Alamat'][0]);
- body.replaceText("{kecamatan}", info['Kecamatan'][0]);
- body.replaceText("{nama_kabupaten}", info['Kabupaten/Kota'][0]);
- body.replaceText("{provinsi}", info['Provinsi'][0]);
- body.replaceText("{tahap}", info['Tahap Bimtek'][0]);
- openDoc.saveAndClose();
- //const tahapan = info['Tahap Bimtek'][0];
- const blobPDF = newTempFile.getAs(MimeType.PDF);
- const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Nama Peserta'][0] + " - " + info['Nama Instansi'][0]);
- tempFolder.removeFile(newTempFile);
- return pdfFile;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement