This document provides a comprehensive explanation of a Google Apps Script designed to send emails when a checkbox is clicked in a Google Sheets document. The script consists of several functions, each serving a specific purpose in the email-sending process.
- Purpose:
- To remind the user to update the
appsscript.jsonfile with the required OAuth scopes before executing the script.
- To remind the user to update the
- Functionality:
- Displays a message reminding the user to update the
appsscript.jsonfile.
- Displays a message reminding the user to update the
- Instructions:
- The user should execute this function after updating the OAuth scopes in the
appsscript.jsonfile.
- The user should execute this function after updating the OAuth scopes in the
- Purpose:
- To provide a centralized location for configuring script settings.
- Functionality:
- Returns an object containing various settings required for the script, such as trigger column, data ending column, recipient column, email subject column, and email body column.
- Instructions:
- The user should modify the settings in this function according to their specific Google Sheets layout.
- Purpose:
- To convert a column letter (e.g., "A", "B", "C") to its corresponding numerical column index (e.g., 1, 2, 3).
- Functionality:
- Accepts a column letter as input and calculates its numerical index.
- Instructions:
- This function is internally used for converting column letters to numerical indices.
- Purpose:
- The main function triggered when a checkbox is edited, responsible for sending emails when the checkbox is checked.
- Functionality:
- Retrieves HTML content for the email from an HTML file named "email.html".
- Identifies the target range and retrieves values from the row where the checkbox was clicked.
- Constructs an email option object with HTML content and other necessary parameters.
- Determines recipient, checkbox value, and email subject from retrieved values.
- Sends an email if the checkbox is checked, logs a message if unchecked, and logs an error if unexpected.
- Instructions:
- The user should ensure proper configuration of script settings and HTML content before triggering this function.
-
OAuth Scopes Update:
- Before executing the script, the user must update the
appsscript.jsonfile with the required OAuth scopes as mentioned in therunToAuthorizeScopes()function.
- Before executing the script, the user must update the
-
Script Configuration:
- Set up the Google Sheets document with checkbox columns.
- Configure script settings using the
scriptSettings()function according to the sheet layout.
-
HTML Content Setup:
- Create an HTML file named "email.html" containing the desired HTML content for the email body.
-
Execution:
- After completing the setup, whenever a checkbox is clicked in the specified trigger column, the script will automatically send an email with the specified content to the recipient mentioned in the specified column.
- It is essential to verify and adjust the script settings according to the specific Google Sheets layout to ensure accurate functionality.
- The HTML content in the "email.html" file should be customized according to the user's requirements for the email body.
- In case of unexpected errors or issues, the user should review the logs generated by the script to diagnose and resolve the problem effectively.
To provide users with a visual reference for how the Google Sheets document should be structured, a demo sheet named "Demo.xlsx" is provided.
Note: Ensure that the demo sheet follows the specified structure and layout to ensure proper functionality of the Google Apps Script.