As a note: I have no experience with JavaScript other than looking at it. I’ve read other posts about using onAfterInsert, but can’t find an example of my situation.
Here’s what I’m asking for if you are able to help:
- How do I tweak the code below to send email to my email address (and a list of others that want to know when someone signs up to play)?
- item.MyEmail; is where I would like to put in my email address as well as the others- how would I do that?
- I don’t understand the sendEmailWithRecipient and the sendEmail parts. Is one for notifying the database administrator and the other for notifying the person who just submitted an entry?
- I turned on Sendgrid/mail under node_modules, is all I have to do is take the working code and plug it in on my data.js file and save?
Pertinent information:
Here’s my website: https://www.jacksoncroquetclub.com. The page with the Submit button I want to hook this to is the Play page. The Events page is the one that has the list of database entries for others to see.
The name of my database is Croquet_Matches
The name of the database fields are: Date, First_Name, Play_Time, More
Any help would be most appreciated.
import {sendEmail, sendEmailWithRecipient} from 'backend/Croquet_Matches';
export function Croquet_Matches_afterInsert(item, context) {
item.MyEmail;
item.Date;
item.First_Name;
item.Play_Time;
item.More;
const subject = `The Mallet's Been Thrown!`;
const body = `We have the date item.Date, the time item.Play_Time, and the challenger item.clientName. Are you up for the challenge? item.More`;
const recipient = item.MyEmail;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response)); }