Skip to main content

Hello,

Is it possible to update multiple records from information in one email?

I know I can use the “When email received” trigger to create a record and extract the body of the email into that record. However, I sometimes receive emails with information that belongs to different records in Airtable.

Initially, I receive an order confirmation. That contains only information about one order, so I can set Airtable up to create a record from each order confirmation.

When the order is ready, I receive another email, and that email often contains information about multiple orders.

The data in the body of the second email is structured roughly like this:

           The ordered materials have arrived.

           Order number: …
           rOther details about the materials]

           Order number: …
            Other details about the materials]

           Order number: …
           Other details about the materials]

           You cannot respond to this e-mail…

The order number is in the initial order confirmation, too.

Is it possible to update the status field of each of the relevant records (orders) that I created from the order confirmations?

Feel free to ask if my explanation doesn’t make sense. English is not my first language.
Thanks,
Lene

Hm yeah, you could try putting the full text of the email into a long text field, then using formula fields to extract the order details either with the REGEX formulas or lots of SUBSTITUTES.  This works but would be pretty clunky, you’d need to have one field per order in the second email, which is fine if there are like 5 maximum or something, but if it goes to dozens this is pretty tedious

You’d also then need to create an automation that would run per field here too

---

If you’re comfortable with scripting (or using ChatGPT) then that works too, you’d get the script to extract the data and output it into an array, then use a Repeating Group on the array to find and update one record per Order Number

I’d recommend doing the script option if possible; it’s cleaner and easier to maintain overall I think

Can you provide an example of the second email’s text?

 

Hey ​@LDKottal,

Regex/script would probably be more error prone.  However, a diferent approach would be to have an AI action on your automation (see more here, on Airtable’s official support article).

You could feed the body of the email to the AI action, and ask it to output a list of order numbers.
Then you could use a repeating group to go through each order number on such list.
Then you could have a Find Records action within the repeating group, to find the corresponding record based on the order number.
For last you could have an Update record action after the Find Records, and within the repeating group, to update the corresponding record.

If you need any help setting this up, please feel free to grab a slot using this link. I’d be happy to show you around!

Mike, Consultant @ Automatic Nation 
YouTube Channel


ChatGPT suggested using this script. “bestillingsnummer” is order number. Might that work?

 

let inputConfig = input.config();

let recordId = inputConfig.recordId; // ID of the Incoming Emails record

let emailBody = inputConfig.emailBody;

// Split email body into blocks (separated by blank lines)

let blocks = emailBody.split(/\n\s*\n/);

// Reference to your Orders table

let ordersTable = base.getTable("Orders");

// Get only records with Status = "Ordered"

let query = await ordersTable.selectRecordsAsync({

    fields: i"Bestillingsnummer", "Status"]

});

let orderedRecords = query.records.filter(r => r.getCellValue("Status") === "Ordered");

// Go through each block

for (let block of blocks) {

    let lines = block.split("\n");

    let data = {};

    for (let line of lines) {

        if (!line.trim()) continue;

        let blabel, ...rest] = line.split(":");

        if (!label || !rest.length) continue;

        let value = rest.join(":").trim();

        let cleanLabel = label.trim();

        datalcleanLabel] = value;

    }

    if (data"Bestillingsnummer"]) {

        // Find matching order among "Ordered" records only

        let matching = orderedRecords.find(

            r => r.getCellValue("Bestillingsnummer") == data "Bestillingsnummer"]

        );

        if (matching) {

            let updates = {

                "Status": "Ready"

            };

            if (data"Ønsket benyttelsesdato"]) {

                updates"Ønsket benyttelsesdato"] = datat"Ønsket benyttelsesdato"];

            }

            await ordersTable.updateRecordAsync(matching.id, updates);

            console.log(`Updated order ${datai"Bestillingsnummer"]}`);

        } else {

            console.log(`No matching "Ordered" record for Bestillingsnummer ${data/"Bestillingsnummer"]}`);

        }

    }

}


Hard to say without an example of your full email text I’m afraid.  When you tried it out did it work right?