I am trying to get a script running that takes multiple file IDs from a Google Sheet and attaches them to an email. I cannot get multiple files to be attached using DriveApp.getFileById.
The script runs and fires off an email, but with no attachments.
function createAndSendDocument(values) {
// Get the email address of the active user
var email = Session.getActiveUser().getEmail();
// Get the name of the document to use as an email subject line.
var subject = 'New Paperwork';
//Let's add the attachments variables
var attachmentstring = values["Which documents do you want to attach?"];
var array = attachmentstring.toString().split(",");
var blobs = [];
var x = 0;
for (var i = 0; i < array.length; i++) {
//check if even
if (i % 2 === 0) {
blobs[x] = array[i];
x++;
}
}
// Append a new string to the "url" variable to use as an email body.
var body = 'your doc: ' + blobs[0] + blobs[1] + array[0] + array[1] + "length:" + array.length;
// Send yourself an email with a link to the document.
GmailApp.sendEmail(email, subject, body, {attachments: blobs});
}
I edited the original post to include the snippet of code. Here is the output of the blobs and array.
undefinedundefinedW-4 2019.pdf1YjQqFNze8VX0L6wZ9O3Y9AJNznR8jfxqlength:4
The script runs and fires off an email...
, can you provide the latest script? 2. About loop process of array, is this thread useful? About your situation, can you provide more information? 1. Are all file IDs inarray
correct values? 2. What kinds of files do you want to use? When you add the information, can you update your question? I think that those information will help users think of about your issue. – TanaikeundefinedundefinedW-4 2019.pdf1YjQqFNze8VX0L6wZ9O3Y9AJNznR8jfxqlength:4
. 2. Can you provide the values ofarray
? Of course, please remove your personal information. 3. If you want to retrieve the values of index with the even number fromarray
and those values are the file IDs, could you please modifyblobs[x] = array[i]
toblobs[x] = DriveApp.getFileById(array[i]).getBlob()
and try again? – Tanaike