Google Apps Script: Consolidating Multiple Converted Docs into a Single Document

Hey everyone,

I’m working on a project to make our form submission process more efficient. Right now, we have a Google Form linked to a spreadsheet. When an employee submits the form, a script creates a new Google Doc for each submission.

What I want to do is have all these submissions go into one big Google Doc instead of creating lots of separate ones. This way, employees can see all their submissions in one place.

Here’s what I’m thinking:

  1. Keep the current script that converts form data to a Google Doc
  2. Add a new part that copies this new doc into a main document
  3. Delete the individual doc after copying

Is this doable with Apps Script? Has anyone tried something similar?

Here’s a simplified version of what I’m using now:

function handleSubmission(event) {
  const data = event.values;
  const mainFolder = DriveApp.getFolderById('abc123');
  const template = DriveApp.getFileById('xyz789');
  
  const newDoc = template.makeCopy('Submission ' + data[0], mainFolder);
  const doc = DocumentApp.openById(newDoc.getId());
  
  doc.getBody().replaceText('{{Name}}', data[1]);
  doc.getBody().replaceText('{{Date}}', data[2]);
  // More replacements...
  
  doc.saveAndClose();
}

Any ideas on how to modify this to achieve what I’m after? Thanks!

hey livbrown, i’ve done something similar before. you’re on the right track! instead of creating new docs, try appending to an existing one. Use DocumentApp.openById() for your main doc, then getBody().appendParagraph() to add new content. Don’t forget doc.saveAndClose() at the end. lmk if u need more help!

Your approach is sound, and it’s certainly achievable with Apps Script. To consolidate submissions into a single document, you’ll need to modify your existing script. First, create a main document to store all submissions. Then, in your handleSubmission function, open this main document and append the new submission data to it. Here’s a rough outline:

  1. Open the main document using its ID.
  2. Get the body of the main document.
  3. Create a new paragraph with the submission data.
  4. Append this paragraph to the main document.
  5. Save and close the main document.

Remember to add page breaks or clear formatting between submissions for readability. You might also want to consider adding a table of contents or bookmarks for easy navigation, especially if you expect a large number of submissions. Let me know if you need more specific guidance on implementation.