Hi everyone!
I have a follow up survey that we send to customers via Airtable form. No prefilled info, pretty simple rating, feedback, and customer email to be filled out. Here's the kicker - we got a response back, and the customer entered @gmail.con instead of @gmail.com. The problem is, I have several follow on automations that are dependent on that email field to match it to the original survey request and then update both records accordingly, notify the user, etc. I already have modifiers on my other automations that corrects any caps to all lowercase, trim, etc to ensure the data is clean and matches. I considered using the "length" modifier, but considering I have no way of knowing how long any given customer's email address will be, that's not really an option.
Now, I know I COULD just manually correct the email address, but I don't want to do that every time, and that also effectively avoids the trigger for one of my automations, "when form is received" do XYZ.
I'm probably going to have to code something in JS and run the automation as a script, but I'm not really sure how to do that, and that's where I'm hoping you guys can help! Does anyone have sample code to replace text in my {Customer Email} field, while leaving the correct text alone? Some sort of replace ".con" with ".com" in that field only. Not sure if it's needed, but the table itself is called "Re-Surveys".
Hoping something like this would work? I'm getting an error still, and not sure why.
let inputConfig = input.config();
let email = inputConfig.Email;
let recID = inputConfig.Record;
let table = base.getTable("Re-Surveys");
async function updateRecord() {
const recordId = recID;
console.log("recID: "+recID)
console.log("recordID: "+recordId)
const stringValue = email.replace(".con",".com")
console.log("stringValue: " + stringValue)
try {
const updatedRecord = await table.update(recordId, {
'Customer Email': stringValue
});
console.log('Record updated:', updatedRecord);
} catch (error) {
console.error('Error updating record:'+error);
}
}
updateRecord();