Google Appscript: unexpectedly stopped executing

Michelleaneous

New Member
Joined
Feb 16, 2024
Messages
13
Office Version
  1. 365
Platform
  1. Windows
AppScript was running last 11Sept and unexpected stopped executing 19Sept

These are the errors:
1726821359560.png

1726821445886.png


Here's the full script:

JavaScript:
function afterFormSubmit(e) {
 
  const info = e.namedValues; 
  const pdfFile = createPDF(info);
  const entryRow = e.range.getRow();
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PDFs").getRange(entryRow,19).setValue(pdfFile.getUrl());

  sendEmail(e.namedValues['Email Address'][0],pdfFile);
 
}

function sendEmail(email,pdfFile) { 
 
  GmailApp.sendEmail(email, "Here's your Material Requisition Form", "Hello,\n\nThank you for submitting a material requisition. \n\nAs this is a self declaration form there is no further approval required. \n\nPlease print and attach this form to all requested materials. \n\nMany thanks for your cooperation. \n\nKind regards,\nLogistics Team", {
    attachments: [pdfFile],
    name: 'Logistics Team'   
  });
  GmailApp.sendEmail("cda.tua1-cim.mailbox@valeo.com", "Material Requisition Form for SAP Transaction", "Hello,\n\nKindly transact the following material requisiton form in SAP. \n\nMany thanks for your cooperation. \n\nKind regards,\nLogistics Team", {
    attachments: [pdfFile],
    name: 'Logistics Team'   
  });
}


function createPDF(info) {
        
  const pdfFolder = DriveApp.getFolderById("1GiY42M3rTq36M9pnUq7Y6RE1qQ8TFN8X");
  const tempFolder = DriveApp.getFolderById("1bkzpVTURICEvcJWemFGaOYTZSdeF_XNj");
  const templateDoc = DriveApp.getFileById("1UfFzcIdG1DCAYpk-NWSiA7bEoz1ZSJXeuV_9-Okw_vg");

  const newTempFile = templateDoc.makeCopy(tempFolder);

  const openDoc = DocumentApp.openById(newTempFile.getId());
  const body  = openDoc.getBody();
  body.replaceText("{{Date of Request}}", info['Date of Request'][0]);
  body.replaceText("{{Requestor}}", info['Requestor'][0]);
  body.replaceText("{{Line}}", info['Line'][0]);
  body.replaceText("{{Cost Centre}}", info['Cost Centre (if known)'][0]);
  body.replaceText("{{Project Name}}", info['Project Name'][0]);
  body.replaceText("{{Project Code}}", info['Project Code'][0]);
  body.replaceText("{{PN}}", info['Part Number or Serial Number'][0]);
  body.replaceText("{{Reason for Requirement}}", info['Reason for Requirement'][0]);
  body.replaceText("{{Quantity}}", info['Quantity'][0]);
  body.replaceText("{{Description}}", info['Description'][0]);
  body.replaceText("{{Have}}", info['Have these products been deemed scrap by the Linelead/Area owner?'][0]);
  openDoc.saveAndClose();


  const blobPDF = newTempFile.getAs(MimeType.PDF);
  const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Requestor'][0] + " " + info['Date of Request'][0]);
  tempFolder.removeFile(newTempFile); 
  return pdfFile;
}
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,221,566
Messages
6,160,525
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top