Michelleaneous
New Member
- Joined
- Feb 16, 2024
- Messages
- 13
- Office Version
- 365
- Platform
- Windows
AppScript was running last 11Sept and unexpected stopped executing 19Sept
These are the errors:
Here's the full script:
These are the errors:
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;
}