Dec 19, 2024 03:46 PM
I am new to scripting. I have two tables: Contacts, and Outreach that are linked via the "Full Name" field with a 1:n relationship. So each Contact (say, for example, "Jane Doe") can have multiple Outreach records. Each Outreach record represents an email or call to that person.
I'd like to write a script that opens a "mailto:" link to the Contact's email address and then creates a record in Outreach with the current date/time stamp that is linked to that contact (in this case, "Jane Doe")
How can I create a script to do this?
Dec 27, 2024 04:19 PM
Hello, try this:
1. Open a mailto: link for the selected contact's email address.
2. Create a new record in the Outreach table, linking it to the selected contact and adding a timestamp.
let contactTable = base.getTable("Contacts");
let outreachTable = base.getTable("Outreach");
let contactRecord = await input.recordAsync("Select a contact", contactTable);
if (!contactRecord) {
output.text("No contact selected. Exiting script.");
return;
}
let email = contactRecord.getCellValue("Email");
let fullName = contactRecord.getCellValue("Full Name");
if (!email) {
output.text("The selected contact does not have an email address. Exiting script.");
return;
}
let mailtoLink = `mailto:${email}`;
output.text(`Opening email client for: ${email}`);
window.open(mailtoLink);
await outreachTable.createRecordAsync({
"Full Name": [{ id: contactRecord.id }] (link the record to the selected contact)
"Date/Time": new Date().toISOString() (Add a timestamp)
});
output.text(`Outreach record created for ${fullName}.`);
If mailto links fail to open directly from the script due to restrictions, you can display the link as text for manual use.
Also, ensure the field names (Email, Full Name, and Date/Time) match your actual table setup.
Let me know if you need more detailed instructions or explanations. Hope it helps.
Dec 31, 2024 03:38 AM
Hello,
нere’s how you can achieve this:
1. Open a mailto: link using the selected contact's email address.
2. Add a new entry in the Outreach table, linking it to the selected contact and recording the current timestamp.
let contactTable = base.getTable("Contacts");
let outreachTable = base.getTable("Outreach");
Prompt the user to select a contact from the Contacts table - let contactRecord = await input.recordAsync("Select a contact", contactTable);
Exit the script if no contact is chosen:
if (!contactRecord) {
output.text("No contact selected. Script terminated.");
return;
}
Retrieve the email and full name of the chosen contact:
let email = contactRecord.getCellValue("Email");
let fullName = contactRecord.getCellValue("Full Name");
Exit if the contact does not have an email address:
if (!email) {
output.text("The selected contact lacks an email address. Script terminated.");
return;
}
Сreate and open the mailto: link in the default email client:
let mailtoLink = `mailto:${email}`;
output.text(`Opening email client for: ${email}`);
window.open(mailtoLink);
Create a new record in the Outreach table, linking it to the selected contact and adding the current timestamp:
await outreachTable.createRecordAsync({
"Full Name": [{ id: contactRecord.id }], // Associate with the contact.
"Date/Time": new Date().toISOString() // Record the timestamp.
});
output.text(`Successfully created an outreach record for ${fullName}.`);
If `mailto:` links don’t open directly due to restrictions, display the link for manual use.
Also, ensure that your field names (Email, Full Name, and Date/Time) align with your actual table configuration.
Let me know if you need further clarification or guidance.