I am quite new to coding as a whole and do not have much experience with Javascript, i am trying to insert an image from my Google Forms response page (which inputs it as a drive link e.g "https://drive.google.com/file/d/17mMFxpUv1s9wI0mixQMKXQd6ojWaamJb/view")
Here is my code as of now.
function onFormSubmit(e) {
var formId = '17pmzdoPjnw_yztuRkEdaoAokxLTlbKyAibN5-_nGN-k';
var form = FormApp.openById(formId);
var formResponses = form.getResponses();
var latestResponse = formResponses[formResponses.length - 1];
var itemResponses = latestResponse.getItemResponses();
var formData = {};
for (var i = 0; i < itemResponses.length; i++) {
var itemResponse = itemResponses[i];
var question = itemResponse.getItem().getTitle();
var response = itemResponse.getResponse();
formData[question] = response;
}
var firstName = formData['First Name'];
var surname = formData['Surname'];
// Get the current timestamp
var timestamp = Utilities.formatDate(latestResponse.getTimestamp(), 'GMT', 'dd/MM/yyyy');
// Specify the Google Docs template file ID
var templateFileId = '1YX6D2j97TcC4T8Z_32G5Fehyf4xvoaEBs7mI5nwl0a0';
var destinationFolderId = '17PLrLo19QUQNTq2o-QzXkM0EutSHN-XO'; // Replace with your Destination Folder ID
// Make a copy of the template file
var copiedFile = DriveApp.getFileById(templateFileId).makeCopy();
// Move the copied file to the destination folder
DriveApp.getFolderById(destinationFolderId).addFile(copiedFile);
// Get the destination document ID
var destinationFileId = copiedFile.getId();
// Open the destination document
var doc = DocumentApp.openById(destinationFileId);
// Replace placeholders in the document with form response data
for (var field in formData) {
var value = formData[field];
doc.getBody().replaceText("{{" + field + "}}", value);
}
// Replace the {{Timestamp}} placeholder with the actual timestamp
doc.getBody().replaceText('{{Timestamp}}', timestamp);
// Save and close the document
doc.saveAndClose();
// Rename the document
var destinationFile = DriveApp.getFileById(destinationFileId);
var newName = firstName + ' ' + surname;
destinationFile.setName(newName);
// Log the new file name for verification
Logger.log('Renamed file to: ' + newName);
}
This handles the placeholders perfectly but does not work with the images.
Some side information
The header is "Photograph Card" and the placeholder is "{{Photograph Card}}"
Currently the placeholder is just outputting the file ID "17mMFxpUv1s9wI0mixQMKXQd6ojWaamJb" as an example.
Any help would be appreciated.
Many thanks,
I have tried the code i mentioned above