Skip to main content
Question

Dynamic email using a placeholder from another table (Ex : replace {{placeholder}} with linked record value)

  • December 3, 2025
  • 1 reply
  • 25 views

Forum|alt.badge.img+2

Hello and thanks in advance for reading and for your help ! :)
 

I have a table called Modeles_de_mails where I store email templates.
One field, Objet_du_mail, contains a subject with a placeholder that look like this :

Nouvelle demande d’intervention {{Ressource}}


In another table, Locations_ressources, I have a field named Ressource that contains the actual value I want to insert (for example: Planétarium).

 

My goal is to automatically update the subject line so it becomes:

Nouvelle demande d’intervention Planétarium  

based on the linked record’s Ressource value.

 

I want to know:

  • What is the correct way to replace a placeholder like {{Ressource}} with the value coming from a linked table?

  • Do I have to use a Lookup field to bring the value into the template table, or is there any cleaner method? I saw some database good practice that tell to avoid as much as possible lookups and formulas inside database to avoid calcul and loading time. 

  • Is there a recommended pattern for managing email templates with variables in Airtable?

Any advice or examples of clean setups would be appreciated.
Thanks a lot, 
Eva

1 reply

Forum|alt.badge.img+2
  • Author
  • New Participant
  • December 3, 2025

Forgot to add, I’m currently using this small script (see bellow), if it ever help someone else.

But as I’m working with non profit organisation, the goal is for them to be nearly autonomous so I would prefer a visual solution they can easily edit.

I didn’t put email inside automation directly cause we have 11 emails (1 email = 1 step) and I would like to keep an eye and keep them editable without having to go on a Texte-to-HTML page. 

Maybe I’m too greedy and will end up doing that :)
 

let { enregistrement, texte_a_remplacer } = input.config();

let table = base.getTable("Locations_ressources");
let record = await table.selectRecordAsync(enregistrement);

// Use the first item if texte_a_remplacer is a list
let template = Array.isArray(texte_a_remplacer) ? texte_a_remplacer[0] : texte_a_remplacer;

// Unescape underscores in the whole template
template = template.replace(/\\_/g, "_");

// Replace all {{variable}} occurrences safely
let outputText = template.replace(/{{(.*?)}}/g, (match, fieldName) => {
// Safely get value; returns undefined if field doesn't exist
let value;
try {
value = record.getCellValue(fieldName);
} catch (err) {
value = undefined; // field doesn't exist
}

// Convert value to string or empty if undefined/null
if (value === undefined || value === null) return "";

// If value is an array (linked records or multi-select), join names
if (Array.isArray(value)) return value.map(v => v.name || v).join(", ");

return value.toString();
});

// Return result
output.set("Texte_avec_variables_remplacees", outputText);