The following Google Apps Script aims to provide one way to solve the difficulty of passing Google Form data into a Google Doc, after the Form has been submitted, where you have a file upload question and you want a nice accessible link putting in the Google Doc rather than the long (unclickable) URL.
I have a specific blog post which focusses more upon the process of creating Google Docs from a Form submission.
![]() |
Google Doc with Form data and accessible file links |
The Code
We will just focus upon getting the relevant keyword tag in the Google Doc for the file upload question and replacing it with our nice accessible and clickable links.
First we need to search our Google Doc body and get the element that is returned. This allows us to then narrow down the exact cell in the table we require (in this example):
var searchResult = docbody.findText("<<fileUpload>>");
var para = searchResult.getElement();
var cell = para.getParent().getParent().asTableCell();
From here we can then focus on separating out the URLs that come from the submitted Form data and actioning them in-turn. We pull out their file ID, use the DriveApp to get the file so we can get its' name, then append a paragraph to our table cell ensuring we make it clickable.
files.split(', ').forEach((linkUrl) => {
var fileId = linkUrl.match(/[-\w]{25,}/);
var linkName = DriveApp.getFileById(fileId).getName();
cell.appendParagraph(linkName).setLinkUrl(linkUrl);
cell.appendParagraph("");
});
Download
Get Google Form file upload links into a Google Doc folder (please use 'File' > 'Make a copy' for your own version).
No comments:
Post a Comment