调用setCollectEmail(true)后,如何用Google Apps Script禁用Google表单的Response receipt?
setCollectEmail(true) in Google Apps Script Hey there, I’ve been in your exact situation before—super annoying when Google Forms forces that response receipt toggle on automatically, and the native FormApp service doesn’t give you a straightforward way to turn it off. Let me walk you through the workaround I found:
The Problem
When you call form.setCollectEmail(true) in Apps Script, Google Forms automatically enables the "Response receipt" option for respondents. Unfortunately, the basic FormApp library doesn’t include a direct method to disable this. To fix this, we need to use the Google Forms API (a more powerful, advanced tool) to tweak that setting.
Step 1: Enable the Forms API in Your Script Project
First, you need to turn on the Forms API for your Apps Script project:
- Open your script editor, go to Extensions > Apps Script.
- Click on Services > Add Service, find Forms API in the list, and click Add.
- Note: This will also enable the API in your linked Google Cloud Console project, but if you run into permission issues later, double-check that the Forms API is enabled there too.
Step 2: Write the Code to Disable Response Receipts
Here’s a reusable function that uses the Forms API to turn off the response receipt setting. Call this right after enabling email collection:
// Helper function to disable response receipts for a given form function disableResponseReceipt(formId) { const updateRequests = [{ updateSettings: { settings: { enableResponseReceipts: false }, updateMask: "enableResponseReceipts" } }]; // Send the update request to the Forms API Forms.Forms.batchUpdate({ requests: updateRequests }, formId); } // Example: Create a form and disable auto-enabled response receipts function createCustomForm() { // Create your form as usual const newForm = FormApp.create("My Custom Form"); // Enable email collection (this turns on receipts by default) newForm.setCollectEmail(true); // Immediately disable the response receipt setting disableResponseReceipt(newForm.getId()); }
How It Works
- The
updateSettingsrequest targets theenableResponseReceiptssetting and sets it tofalse. - The
updateMasktells the API exactly which setting we want to modify, so it doesn’t touch any other form configurations.
Quick Notes
- Make sure your script has the necessary permissions to modify the form—when you run the function for the first time, you’ll be prompted to authorize it.
- If you’re modifying an existing form instead of creating a new one, just pass the existing form’s ID to
disableResponseReceipt().
内容的提问来源于stack exchange,提问作者Arthur CROS

