📨 A range of communication examples
Basic Send Email
This example will work on an individual entry where we get the current entry, and send an email. This will merge data into the email template from the entry selected.
async function script(C) {
const currentEntry = await C.getCurrentEntry();
const emailInput = {
entryId: currentEntry.recordValueId,
recordInternalId: 'standard-contacts',
from: {
email: "[email protected]",
name: "ABC Company"
},
to: ["[email protected]"],
templateId: 111111, // your email template you want to send
};
const response = await C.sendEmail(emailInput);
C.log(response);
}Send Email to a Linked select field
In this example, we'll send an email to an "Assigned To" field. This is where a select field is linked to different record and we want the email to go that person. But we need to find their email address.
In this specific example, we might be sending a notification to the employee that they have been assigned a project.
async function script(C) {
const projectEntry = await C.getCurrentEntry();
const assignedTo = projectEntry["assigned-to"] && projectEntry["assigned-to"][0];
if (assignedTo) {
const assignedToEntry = await C.getEntries({
entryIds: [assignedTo],
recordInternalId: 'employees',
});
const emailInput = {
entryId: 11111,
recordInternalId: 'projects',
from: {
email: "[email protected]",
name: "ABC Company"
},
to: [assignedToEntry.email],
templateId: 280953
};
const response = await C.sendEmail(emailInput);
C.log(response);
}
}Send Email replacing tags inside of an Email Templates
This example will demonstrate how to get the contents of an email template, but also allow you to replace a tag inside of the email template. An example might be to insert a table of data, or a calculated value.
aasync
function script(C) {
const {
entryId,
recordInternalId
} = C.getEvent();
const emailInput = {
entryId: entryId,
recordInternalId: recordInternalId,
templateId: 280953
};
const response = await C.mergeEmailTemplate(emailInput);
const subject = response.subject; // Gets the Subject of the email template
let body = response.body; // Gets the email body
body = body.replace("{custom_data}", "Hello world! This was changed"); // Replaces a custom tag with the content you would like
const sendEmailResponse = await C.sendEmail({
entryId: entryId,
recordInternalId: recordInternalId,
from: {
email: "[email protected]",
name: "ABC Company"
},
to: ["[email protected]"],
subject: subject,
body: body
});
return {
sendEmailResponse
};
}📌 Need Help?
