This is an old revision of the document!
Table of Contents
High-Level Overview
The script generates and updates an email body template with dynamic content based on specific Airtable data. It fetches relevant records, processes information (e.g., agenda items, tasks, and member details), replaces placeholders in an email template with real data, and updates an Airtable record with the final email body and status.
Detailed Steps and Functionality
1. Initial Setup
- Retrieves input parameters via `input.config()` including IDs (`Email_Rec_ID`, `Member_Rec_ID`), names, and dates.
- Defines constants such as templates for the email body (`Body_Template_Long`), deadlines, HTML styling, and placeholders for dynamic content.
2. Fetch Member Details
- Uses `BoardMembersTable` (likely linked to the “Worklist” table) to fetch information about a specific member (`Member_Rec_ID`) including email, nickname, and full name.
- Logs details for debugging purposes.
3. Fetch Secretary Details
- Queries the “Officers” view of the “Members” table to find the record of the secretary (identified by their role in the “Office” field).
- Extracts the secretary's email and nickname for inclusion in the email template.
4. Populate Email Template
- Replaces placeholders in the email body (`Body_Template`) with dynamically fetched data:
- `[NICKNAME]`, `[MEETING TITLE]`, `[MEETING DATE]`, `[AGENDA FORM]`, `[AGENDA DEADLINE]`, `[SECRETARY EMAIL]`, `[SECRETARY NAME]`, etc.
5. Generate Agenda List
- Queries the “Board Meeting Agenda Items” table to find agenda items associated with the specified meeting (`Meeting_Title`).
- Constructs an HTML list of agenda items with links and presenters, replacing the `[AGENDA_LIST]` placeholder in the email body.
6. Generate Work List
- Queries the “Board Meeting Tasks” view of the “Worklist” table to find tasks assigned to the current member (`Member_Full_Name`).
- Constructs an HTML list of tasks, marking overdue tasks with red text (`Overdue_HTML`), and replaces the `[WORK_LIST]` placeholder in the email body.
7. Update Airtable Record
- Updates the record in the “emails” table (`Email_Rec_ID`) with:
- The completed email body (`Email_Body_Field`).
- The status “Send” (`Email_Status_field`).
8. Utility Function
- Provides a helper function `unselectOption` to remove specific options from a multi-select field in a record. This function is defined but commented out in the script.
9. Logging
- Logs various details such as fetched data, email body, and debugging messages for development and troubleshooting.
Key Variables
Dynamic Inputs
- `Email_Rec_ID`, `Member_Rec_ID`, `Agenda_Form`, `Meeting_Title`, `Meeting_Date`, etc., are dynamically provided through `input.config()`.
Static Placeholders in the Template
- `[NICKNAME]`, `[MEETING TITLE]`, `[MEETING DATE]`, `[AGENDA FORM]`, `[SECRETARY NAME]`, `[AGENDA_LIST]`, `[WORK_LIST]`.
Tables and Views Accessed
- `emails` (primary table being updated).
- `Board Meeting Members` or `Worklist` (member data).
- `Members` (officers and roles).
- `Board Meeting Agenda Items` (agenda details).
- `Worklist` (tasks assigned to members).
Purpose
The script automates the creation of meeting-related emails by:
- Personalizing the email content based on member data and meeting context.
- Dynamically generating agenda and task lists.
- Updating the email record in Airtable for distribution.
Potential Improvements
1. Error Handling
- Add error handling for missing data (e.g., null fields, empty records).
- Ensure fallback values for placeholders if data is not found.
2. Code Optimization
- Consolidate repetitive code (e.g., multiple `replace()` calls for the email template).
- Use helper functions for common tasks like placeholder replacement.
3. Scalability
- Ensure it works seamlessly with multiple meetings or larger datasets.