Advertisement
muhidins

tte

Mar 10th, 2022
4,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function afterFormSubmit(e) {
  2.   const info = e.namedValues;
  3.   const pdfFile = createPDF(info);
  4.   const entryRow = e.range.getRow();
  5.   const ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Laporan");
  6.   ws.getRange(entryRow, 1).setValue(pdfFile.getUrl());
  7.   ws.getRange(entryRow, 2).setValue(pdfFile.getName());
  8.   sendEmail(e.namedValues['Email Address'][0], pdfFile, e.namedValues['Tahap Bimtek'][0]);
  9. }
  10.  
  11. function sendEmail(email, pdfFile, tahapan) {
  12.   GmailApp.sendEmail(email, "BIMBINGAN TEKNIS PENYELESAIAN LAPORAN AKHIR DAN TTE BAST TAHUN 2021", "Peserta Bimbingan Penyelesaian Laporan Akhir dan TTE BAST Tahun 2021, " + tahapan, {
  13.     attachments: [pdfFile],
  14.     name: 'Bidang Sarpras Direktorat SMA 2021'
  15.   });
  16. }
  17.  
  18. function createPDF(info) {
  19.   const pdfFolder = DriveApp.getFolderById("1VhhxROSVtUTlC7pQ853e4ciosZe3h4U_");
  20.   const tempFolder = DriveApp.getFolderById("1W_QRvRz2HHxLKA7MDPUWeZzUi86D2g18");
  21.   const templateDoc = DriveApp.getFileById("15BQyFJ-RkcfpvmR_h9t-dfj85Onp2xa95I9eVQpJ0zk");
  22.   const newTempFile = templateDoc.makeCopy(tempFolder);
  23.   const openDoc = DocumentApp.openById(newTempFile.getId());
  24.   const body = openDoc.getBody();
  25.  
  26.   body.replaceText("{nama}", info['Nama Peserta'][0]);
  27.   body.replaceText("{nip}", info['NIP'][0]);
  28.   body.replaceText("{pangkat}", info['Pangkat/Gol'][0]);
  29.   body.replaceText("{jabatan}", info['Jabatan'][0]);
  30.   body.replaceText("{hp}", info['No. Handphone (Whatsapp)'][0]);
  31.   body.replaceText("{email}", info['Email Address'][0]);
  32.   body.replaceText("{nama_instansi}", info['Nama Instansi'][0]);
  33.   body.replaceText("{npsn}", info['NPSN'][0]);
  34.   body.replaceText("{alamat}", info['Alamat'][0]);
  35.   body.replaceText("{kecamatan}", info['Kecamatan'][0]);
  36.   body.replaceText("{nama_kabupaten}", info['Kabupaten/Kota'][0]);
  37.   body.replaceText("{provinsi}", info['Provinsi'][0]);
  38.   body.replaceText("{tahap}", info['Tahap Bimtek'][0]);
  39.   openDoc.saveAndClose();
  40.  
  41.   //const tahapan = info['Tahap Bimtek'][0];
  42.   const blobPDF = newTempFile.getAs(MimeType.PDF);
  43.   const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Nama Peserta'][0] + " - " + info['Nama Instansi'][0]);
  44.   tempFolder.removeFile(newTempFile);
  45.  
  46.   return pdfFile;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement