Help

How do I say IF this email address has product A, check to see if it also has product B

Topic Labels: Formulas
Solved
Jump to Solution
1541 12
cancel
Showing results for 
Search instead for 
Did you mean: 
Shelly_Criswell
5 - Automation Enthusiast
5 - Automation Enthusiast

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?

1 Solution

Accepted Solutions
Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

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):

Screenshot 2023-11-01 172629.png

 

 Field Formulas:

Screenshot 2023-11-01 172716.png

 

Screenshot 2023-11-01 172749.png

 

Screenshot 2023-11-01 172810.png

 

Automation Trigger:

Screenshot 2023-11-01 172840.png

Script Input Variables:

Screenshot 2023-11-01 172932.png

 

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!!

 

 

See Solution in Thread

12 Replies 12
Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

Hey @Shelly_Criswell ! can you provide a screenshot of your table(s)? Helps me to visualize your setup

Kenneth_Raghuna
7 - App Architect
7 - App Architect

Two ways to approach this:

1. Nested IF

IF(Condition A, IF(Condition B, True, False), False)

2. Using the AND() function. This checks to see if multiple conditions are satisfied before returning a True or False value.

Ex. AND(1 = 1, 2 = 2) would return True

AND(1 = 1, 2 = 1) would return False

@Arthur_Tutt If they purchase the PR Starter Pack they have the option to purchase the Go Custom. If just the PR Starter Pack, they have access for 1 year. If they upgrade, they get an additional year. 

Shelly_Criswell_0-1698787393741.png

 

@Kenneth_Raghuna thank you for responding. How would I write that out? Here's a screenshot if that is helpful. 

Shelly_Criswell_0-1698787700139.png

 

Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

@Shelly_Criswell a few more clarification questions. 

So firstly, there's just 1 purchase per record, correct? Something like:

shelly@email.com => PR Starter Pack

shelly@email.com => Go Custom

 

And then you want to run a script that checks the first record, sees that shelly bought the PR Starter Pack, and then checks all other records to see if she also bought the Go Custom? And what kind of output are you looking for? Do you want a field that says "Purchased Another Product" and then just "Yes / No", or you want it to list all other products they purchased? 

Formula calculations can only be done within a single record, so if the data is spread out across multiple records will need to be some kind of automation.

I'm sure your question sounded simple initially, but getting into the weeds gets a bit complicated 🙂

Hey @Arthur_Tutt yes, you're correct it's in separate records, like your example.

And yes, some way to notate when a PR Starter Pack student purchases a Go Custom... I was afraid it was more complicated than I thought. 😩

I understood the problem a little differently initially.

From what it sounds like, the best solution would be an automation, and might even require a script depending on how your sales process itself is structured.

I'm pretty busy today but if you want to shoot me an email I can probably hop on a virtual call tomorrow and give you some assistance:
dillon@bootysattva.productions

Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

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):

Screenshot 2023-11-01 172629.png

 

 Field Formulas:

Screenshot 2023-11-01 172716.png

 

Screenshot 2023-11-01 172749.png

 

Screenshot 2023-11-01 172810.png

 

Automation Trigger:

Screenshot 2023-11-01 172840.png

Script Input Variables:

Screenshot 2023-11-01 172932.png

 

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!!

 

 

Nice Solution @Arthur_Tutt .

Regarding reading data from Select fields: You can eliminate the need for translating to plain text in the table by either using the getCellValueAsString() method, or accessing the "name" property within the object.

Examples of each:

getCellValueAsString("Product")

getCellValue("Product").name

 

You can also get the record ID within the script by accessing the "id" property:

purchaseRecords[i].id

 

If the logic flow for the sales transactions themselves only allow for purchasing the "Go Custom 1" AFTER purchasing the "PR Starter Pack", you can significantly reduce the number of runs of the automation by changing the trigger to seek transactions where "Go Custom 1" was purchased. This will require the script to be updated but would pay off in base performance loads as the base grows.

 

@Shelly_Criswell : In order to translate Arthur's solution into extending the expiry dates, you can have the script output a check into a checkbox field titled something like "Extension Purchased" (whatever you want, just make sure it's consistent in the script).

Then you'll need to modify your "Expiration" field. I'm assuming it's just a formula that adds one year to the Purchase date. You'll want to change it to either a SWITCH() or IF() formula that checks to see if the box in "Extension Purchased" is ticked. If it is, add two years, if not, add one year.

 

 

Please note though, that if this log is used to track transactions that may repeat over time, the solution will break.

ie. A client that had a PR Starter Pack + "Go Custom 1" extension decides to purchase just the PR Starter Pack 2 years later. The solution as is would see the old purchase of the extension and add it to the expiry for the newly purchased PR Starter Pack.