I have put together, with the help of some online tutorials,a script that resides in my google sheet, that takes form submissions to generate my letter based on my templates.
Everything is working fine, but at the last part after saving out a PDF file I would like to add to the option to download the file with a pop up question.
"Would you like to download the PDF" [Yes][No]
I'm having trouble understanding how to implement it.
Here is my code without the download option:
function jobFillGoogleDocFromForm(e) {
//e.values is an array of form values
var timestamp = e.values[0];
var jobType = e.values[1];
var jobTitle = e.values[2];
var companyName = e.values[3];
var now = new Date();
var day = now.getDate() +1;
var month = now.getMonth();
var year = now.getFullYear();
var todaysDate = day+'/'+month+'/'+ year
//determine which cover letter template to use based on the job type
if (jobType == '3D Art') {
var file = DriveApp.getFileById('1kENGdn8fALXPle28xHO2SCNsuHZiI1k4ckQhRlHJHoU');
} else {
var file = DriveApp.getFileById('1lSrtlBvzvMiL6YAdSSAUiHvHPVG_DAsopQIo3nr6924');
}
//We can make a copy of the template, name it, and optionally tell it what folder to live in
//file.makeCopy will return a Google Drive file object
var folder = DriveApp.getFolderById('1tS3CRWI2Vrh4RzS96n0I4lrktxLhCL6s')
var copy = file.makeCopy('AndreaMele_Cover_Letter' + '_' + jobTitle + ' - ' + companyName, folder);
//Once we've got the new file created, we need to open it as a document by using its ID
var doc = DocumentApp.openById(copy.getId());
//Since everything we need to change is in the body, we need to get that
var body = doc.getBody();
//Then we call all of our replaceText methods
body.replaceText('{{todaysDate}}', todaysDate);
body.replaceText('{{jobTitle}}', jobTitle);
body.replaceText('{{companyName}}', companyName);
//Save and close the document to persist our changes
doc.saveAndClose();
//Save out a copy as PDF
var docblob = doc.getBlob();
docblob.getAs('application/pdf').setName(doc.getName() + ".pdf");
folder.createFile(docblob);
}
As I can see you're using onFormSubmit
trigger. This action can't interactive with an user.
You can try sent to the user an email with the file or a download link.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.