Hi, I have a Google form that users fill out to submit work orders. I used the help of AI to write a code that sends an automatic email based on the user's response. However, there is a field in the form where the user can upload images. The code works to send the required info; however, it cannot send those images as clickable links in the automated email. Can anyone please help me solve the issue?
function onFormSubmit(e) {
var formResponse = e.response;
var itemResponses = formResponse.getItemResponses();
var email = '';
var subject = 'New Work Order Received';
var body = 'Hello, a new work order has been submitted by RFE.<br><br>';
for (var i = 0; i < itemResponses.length; i++) {
var itemResponse = itemResponses[i];
var title = itemResponse.getItem().getTitle();
var response = itemResponse.getResponse();
switch(title) {
case 'Select Location':
if(response == 'RAC') {
email = '************';
} else if(response == 'MAC') {
email = '*************';
}
break;
case 'Work Order Required':
if(response != 'Yes') {
email = '';
}
break;
case 'Supervisor Name':
case 'Supervisor Email':
case 'Description of the issue':
body += title + ': ' + response + '<br>';
break;
case 'Images':
var fileIds = response.split(', ');
for (var j = 0; j < fileIds.length; j++) {
var file = DriveApp.getFileById(fileIds[j]);
var url = file.getUrl();
body += 'Image ' + (j+1) + ': <a href="' + url + '">Link</a><br>';
}
break;
}
}
if(email != '') {
sendEmail(email, subject, body);
}
}
function sendEmail(email, subject, body) {
MailApp.sendEmail({
to: email,
subject: subject,
body: body,
htmlBody: body
});
}
function setUpTrigger() {
var form = FormApp.openByUrl('link hidden');
ScriptApp.newTrigger('onFormSubmit')
.forForm(form)
.onFormSubmit()
.create();
}
The links that generates in an email work for me although the script assumes the user will upload more than a single file. If they just upload one file it will fail on splitting the response. Do the recipients have access to view the contents of the uploads folder from the form? That's likely the problem.