I have a product that expires in one year. If they purchase an upgrade, it extends the expiration another year. The records are added individually to Airtable. How do I say IF this email address has product A, check to see if it also has product B in another record?
Solved
How do I say IF this email address has product A, check to see if it also has product B

Best answer by Arthur_Tutt
Hey @Shelly_Criswell ! Alright good news, I think I finally understand what you're looking for and developed an automation solution for you. It's a little complicated, but I made a step by step Loom Video here to explain how it works. Here's my example:
*** remember to change my Table / Field / Variable names to match yours exactly or it won't work ***
Table Setup And Expected Output (circled in blue):
Field Formulas:
Automation Trigger:
Script Input Variables:
Automation Script:
// get Purchases Table
var purchaseTable = base.getTable("Purchases"); //UPDATE TO MATCH YOU TABLE NAME
var purchaseQuery = await purchaseTable.selectRecordsAsync({fields: ["Buyer Email", "Product (Hide)", "Transaction Type (Hide)", "Record ID"]}) //UPDATE TO MATCH YOU FIELD NAMES
var purchaseRecords = purchaseQuery.records;
var inputConfig = input.config();
var productName = inputConfig.productName;
var transactionType = inputConfig.transactionType;
var buyerEmail = inputConfig.buyerEmail;
var recordID = inputConfig.recordID;
var purchaseProducts = "";
if (productName == "PR Starter Pack" && (transactionType == "Sale" || transactionType == "Rebill")) { //UPDATE TO MATCH YOU VARIABLE NAMES
for (var i = 0; i < purchaseRecords.length; i++) {
if (buyerEmail == purchaseRecords[i].getCellValue("Buyer Email") && recordID != purchaseRecords[i].getCellValue("Record ID")) {
purchaseProducts = `${purchaseProducts} | ${(purchaseRecords[i].getCellValue("Product (Hide)"))}`
}
}
}
console.log(purchaseProducts)
// Updating Purchased Data
var updates = [{
"id": recordID,
fields: {
"Purchased Other Products?": purchaseProducts
}
}]
console.log(updates)
await purchaseTable.updateRecordsAsync(updates);
Let me know if this works for you!!
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.