Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:10:25+00:00 2026-06-05T12:10:25+00:00

I am using a script to process a form as it is submitted. Part

  • 0

I am using a script to process a form as it is submitted. Part of it involves merging data from the form with a google doc and then emailing that doc as a pdf. Is there anyway to delete the doc once it has been sent?

If it helps, here is my script:

function onFormSubmit(e) {
  //Get Form Values
    var candID = parseInt(e.values[1]);
    var emailAddress = e.values[2];

  //Get Additional Settings
    var ssMaster = SpreadsheetApp.openById("0AierVcXWELCudDY2Y3J2Z1hoX3pLOXYzTW1pOVF3Wmc");
    var settings_sheet = ssMaster.getSheetByName("Settings");
    var candCodeLength = settings_sheet.getRange("B20").getValue();
    var candCodeChars = settings_sheet.getRange("B21").getValue();
    var tempDocumentID = settings_sheet.getRange("B14").getValue();
    var candInfoSheet = ssMaster.getSheetByName("Candidate Information");
    var candInfoLastRow = candInfoSheet.getLastRow();
    var candInfoArray = candInfoSheet.getRange(2,1,candInfoLastRow,7).getValues();

  //Find Corresponding Row for Form Entry
    for(var i=0; i<candInfoArray.length; i++) {
      if (candInfoArray[i][3] === candID) {
        var row = i+2;
        }
      }
     var candIDRowNumber = row;

  //Create & Record Candidate Code
    do { 
      var candCode = createCandCode(candCodeLength, candCodeChars);
      }
      while(checkCandCode(candInfoArray, candCode) === true);
      candInfoSheet.getRange(row,6,1,1).setValue(candCode);
      candInfoSheet.getRange(row,7,1,1).setValue(emailAddress);

  //Create PDF
    var docid = DocsList.getFileById(tempDocumentID).makeCopy("Character Reference Instructions").getId();
    var doc = DocumentApp.openById(docid);
    Logger.log(candInfoArray);
    Logger.log(row);
    var firstName = candInfoArray[(row-2)][1];
    var lastName = candInfoArray[(row-2)][0];
    var body = doc.getActiveSection();
    body.replaceText("<<first>>", firstName);
    body.replaceText("<<last>>", lastName);
    body.replaceText("<<code>>", candCode);
    doc.saveAndClose();

  //Send Email
    var message = "You have successfully completed the NHS Registration form.\n\n Your Candidate Code (different from your Candidate ID) is \"" + candCode + "\" and should be given to your character reference so that they can fill out your character reference form.\n\n If you have any questions, please email Ann Perham at ann_perham@needham.k12.ma.us." ;
    var subject = "NHS Registration Confirmation & Character Reference Instructions";
    var advancedArgs = {name: "Ann Perham", replyTo: "ann_perham@needham.k12.ma.us", attachments: doc.getAs("application/pdf")};
    MailApp.sendEmail(emailAddress, subject, message, advancedArgs);
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:10:26+00:00Added an answer on June 5, 2026 at 12:10 pm

    You can use doc.setTrashed right at the end of your function while it is still the active document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple jQuery script that slides a contact form up from the
I'm working on an intermediary form that will gather some data from the user
We were using a build script to automate our publishing process and it was
I am creating a process using proc_open in one PHP script. How do i
I have a PHP script where I create a new process using proc_open().It executes
Can I run a PHP CGI script as a background process using exec() ?
I am using a script that is sending out emails and I am receiving
I'm using a script that connects to a cluster through ssh and sends some
I'm using a script to move files from one directory to another. It's also
I'm in the process of creating a small currency conversion script using the money.js

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.