Error TypeError: body.replacementText is not a function

70 views
Skip to first unread message

MR YUDAI

unread,
Nov 16, 2023, 3:49:43 PM11/16/23
to Google Apps Script Community
hello guys, really need help here.

im beginner in script,

i follow the tutorial here

============

function myFunction() {
 
}


function createPDF(){


const info = {
  'Email Address': ['msaiful...@gmail.com'],
  'NAMA PENUH': ['MOHAMAD SAIFULLAH BIN SATIN'],
  'NO KAD PENGENALAN': ['881229495017'],
  'JABATAN': ['JAB. FARMASI'],
  'PILIH JAWATAN ANDA': ['PENOLONG PEGAWAI PERUBATAN'],
  'NAMA PENUH JAWATAN ANDA?': [''],
  'GRED JAWATAN': ['U29'],
  'NO TELEFON BIMBIT': ['0198406421'],
  'NO TELEFON PEJABAT': ['835'],
  'JENIS PERMOHONAN': ['PERMOHONAN BARU'],
  'JENIS PROSEDUR': ['CORE PROCEDURES'],
  'SAYA INGIN MEMOHON PROSEDUR BERIKUT': ['ASASA'],
  'NAMA STAF PERTAMA (1)': ['DR FAUZIAH HANIM'],
  'JAWATAN STAF TERSEBUT (1)': ['TIMBALAN PENGARAH PERUBATAN 2'],
  'NAMA STAF KEDUA (2)': ['NURUL'],
  'JAWATAN STAF TERSEBUT (2)': ['PENOLONG PEGAWAI PERUBATAN']
   };

const pdfFolder = DriveApp.getFolderById("1am-au3ijwrPtHfFN16RNf8V6R6SjckfA");

const tempFolder = DriveApp.getFolderById("1jep751PsLFFHDMbqrO3bj-pbTBagGCtY");

const templateDoc = DriveApp.getFileById("1Ca1YgYW-o9x8svLfuk4I5801CCg_KHOzi9Zy6ACQRIA");

const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
body.replacementText("{EA}", info["Email Address"][0]);
body.replacementText("{NP}", info["NAMA PENUH"][0]);
body.replacementText("{NKP}", info["NO KAD PENGENALAN"][0]);
body.replacementText("{JA}", info["JABATAN"][0]);
body.replacementText("{PJA}", info["PILIH JAWATAN ANDA"][0]);
body.replacementText("{NPJA}", info["NAMA PENUH JAWATAN ANDA?"][0]);
body.replacementText("{GJ}", info["GRED JAWATAN"][0]);
body.replacementText("{NTB}", info["NO TELEFON BIMBIT"][0]);
body.replacementText("{NTP}", info["NO TELEFON PEJABAT"][0]);
body.replacementText("{JP}", info["JENIS PERMOHONAN"][0]);
body.replacementText("{JPR}", info["JENIS PROSEDUR"][0]);
body.replacementText("{SIMPB}", info["SAYA INGIN MEMOHON PROSEDUR BERIKUT"][0]);
body.replacementText("{NS1}", info["NAMA STAF PERTAMA (1)"][0]);
body.replacementText("{JST1}", info["JAWATAN STAF TERSEBUT (1)"][0]);
body.replacementText("{NS2}", info["NAMA STAF KEDUA (2)"][0]);
body.replacementText("{JST2}", info["JAWATAN STAF TERSEBUT (2)"][0]);
openDoc.saveAndClose();


const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdffile = pdfFolder.createFile(blobPDF).setName("My PDF");



}

Tanaike

unread,
Nov 16, 2023, 6:45:26 PM11/16/23
to Google Apps Script Community
I think that the Class Body of DocumentApp has no method of "replacementText". In this case, how about replaceText?

But, I'm not sure about your actual situation. So, I'm not sure whether your script has other issues. I apologize.

MR YUDAI

unread,
Nov 17, 2023, 12:33:26 PM11/17/23
to Google Apps Script Community
thanks!!!!!!!! its work!! you are my savior

MR YUDAI

unread,
Nov 17, 2023, 2:33:03 PM11/17/23
to Google Apps Script Community
i have another problem here, i can`t see the Url PDF link on the spreadsheet. i put it on the 20th column.

function afterFormSubmit(e) {
      const info = e.namedValues;
      const pdfFile = createPDF(info);
      const entryRow = e.range.getRow();
      SpreadsheetApp.getActiveSpreadsheet().getSheetByName("People").getRange(entryRow, 20).setValue(pdfFile.getUrl());
 
}


function createPDF(info){




const pdfFolder = DriveApp.getFolderById("1am-au3ijwrPtHfFN16RNf8V6R6SjckfA");

const tempFolder = DriveApp.getFolderById("1jep751PsLFFHDMbqrO3bj-pbTBagGCtY");

const templateDoc = DriveApp.getFileById("1Ca1YgYW-o9x8svLfuk4I5801CCg_KHOzi9Zy6ACQRIA");

const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();

body.replaceText("{EA}", info['Email Address'][0]);
body.replaceText("{NP}", info['NAMA PENUH'][0]);
body.replaceText("{NKP}", info['NO KAD PENGENALAN'][0]);
body.replaceText("{JA}", info['JABATAN'][0]);
body.replaceText("{PJA}", info['PILIH JAWATAN ANDA'][0]);
body.replaceText("{NPJA}", info['NAMA PENUH JAWATAN ANDA?'][0]);
body.replaceText("{GJ}", info['GRED JAWATAN'][0]);
body.replaceText("{NTB}", info['NO TELEFON BIMBIT'][0]);
body.replaceText("{NTP}", info['NO TELEFON PEJABAT'][0]);
body.replaceText("{JP}", info['JENIS PERMOHONAN'][0]);
body.replaceText("{JPR}", info['JENIS PROSEDUR'][0]);
body.replaceText("{SIMPB}", info['SAYA INGIN MEMOHON PROSEDUR BERIKUT'][0]);
body.replaceText("{NS1}", info['NAMA STAF PERTAMA (1)'][0]);
body.replaceText("{JST1}", info['JAWATAN STAF TERSEBUT (1)'][0]);
body.replaceText("{NS2}", info['NAMA STAF KEDUA (2)'][0]);
body.replaceText("{JST2}", info['JAWATAN STAF TERSEBUT (2)'][0]);
openDoc.saveAndClose();


const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName(info['NAMA PENUH'][0] + " " + "Permohonan Privileging");
tempFolder.removeFile(newTempFile);
return pdfFile;


}

Yousuf Ahmed

unread,
Nov 17, 2023, 8:57:30 PM11/17/23
to google-apps-sc...@googlegroups.com
This is my WhatsApp number +8801580441977 please sir massage through in My WhatsApp 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/d190702d-3e2d-4588-af0c-3414fc8a9268n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages