Help

Help with airtable matching record script

Topic Labels: Automations
Solved
Jump to Solution
591 5
cancel
Showing results for 
Search instead for 
Did you mean: 
kofal
5 - Automation Enthusiast
5 - Automation Enthusiast

Hey everyone,

I am slowly moving forward in my airtable scripting journey. What a ride so far. 

I would need some advice on best proceeding to finalize my script.

Context:

I created a script triggered from a button, to match client records with potential real estate properties, based on a set of preferences such as the number of bedrooms, the type of view, or some house features. 

The script does the following steps:
- Fetch the criteria value from the record used for the automation (the client)
- for each record in my property listings, it calculates a base score for each criterion (0 to 10)
- It applies a weight point system to the criteria scores and outputs a Total property score (normalized from 0 to 10)
- I then slice the top 10 properties and link the IDs to the client record under a specific linked field. 

Can't lie, as a no-code person, it took me a few days to get there.

Currently, the criteria weight points are fixed, and stored in a const. This works but some extra flexibility would be ideal.

I am thinking about adding more control for the user when executing the script, allowing him to select the importance of each criterion for the client before running the script, hence using dynamic weight point values.

Any opinion on the best method to apply here?

Option A:
- I could define the weight points in the client record beforehand, and fetch them when executing the script. 

Option B:
- I could prompt the user to select the weight point upon triggering the automation. Which I would have no clue how to do. 

1 Solution

Accepted Solutions
Kenneth_Raghuna
7 - App Architect
7 - App Architect

If you decide to do option B by using the a Button to trigger the script, look at the API reference for the input.textAsync method.

This allows you to ask for user input. Note that you need to turn the input variable into an integer (assuming that you limit weighting to integers), and that you'll want to make sure to validate the data before you perform operations with it (check to see if you have an integer, ask for an integer again if they enter something different).

 

Here's a short example:

 

let inputBedWeight = await input.textAsync('Assign a weight to # of bedrooms');
let bedWeight = Number(inputBedWeight)

while (!Number.isInteger(bedWeight)) {
    console.log(`Input is not an integer. Try again.`)
    inputBedWeight = await input.textAsync('Assign a weight to # of bedrooms');
    bedWeight = Number(inputBedWeight)
}

console.log(`${bedWeight} is an integer!`)

 

See Solution in Thread

5 Replies 5
Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

Hey @kofal congratulations that sounds like a pretty complex script for someone who's 'no code' 😊

Regarding your options A and B. The quick answer is that Option B is not an available option if you want this to run as an automation (automations do not allow for user inputs). However you did say it is triggered by a button.  

Quick clarification, are you running your script within the 'Automation' section, or are you running using the scripting extension. Because yes through the scripting extension you can ask for user input. 

For me personally, I would use option A. In the record I'd have a field (or multiple fields if there's multiple weightings) where the user inputs their weighting from 1-10, and then make it a requirement of the trigger that those fields must contain data (trigger will not execute if blank). 

But sounds like you're most of the way there - nicely done! 

Kenneth_Raghuna
7 - App Architect
7 - App Architect

If you decide to do option B by using the a Button to trigger the script, look at the API reference for the input.textAsync method.

This allows you to ask for user input. Note that you need to turn the input variable into an integer (assuming that you limit weighting to integers), and that you'll want to make sure to validate the data before you perform operations with it (check to see if you have an integer, ask for an integer again if they enter something different).

 

Here's a short example:

 

let inputBedWeight = await input.textAsync('Assign a weight to # of bedrooms');
let bedWeight = Number(inputBedWeight)

while (!Number.isInteger(bedWeight)) {
    console.log(`Input is not an integer. Try again.`)
    inputBedWeight = await input.textAsync('Assign a weight to # of bedrooms');
    bedWeight = Number(inputBedWeight)
}

console.log(`${bedWeight} is an integer!`)

 

kofal
5 - Automation Enthusiast
5 - Automation Enthusiast

@Arthur_Tutt Thank you for the feedback!

Yes currently, I am running the script from the automation feature, which is triggered by a button. 

So essentially, if I summarize what you are both saying, either I use fields to save weight values, or I have to convert my automation into a scripting app to allows a multi-step input request. 

From an MVP point of view, it seems easier to implement option A and see if this truly add values before going full script mode 😄 

kofal
5 - Automation Enthusiast
5 - Automation Enthusiast

@Arthur_Tutt I honestly have to thank chatGPT for my script.

For all the Nocode people out there, it's possible to come up with something fairly advanced as long as you have a basic understanding of the scripting logic requirements with airtable. It obviously isn't 100% clean and most likely, there would be a better way to create the functions I have implemented + GPT is a pain. But it works

 

Arthur_Tutt
8 - Airtable Astronomer
8 - Airtable Astronomer

@kofal ChatGPT is also my (not so) secret weapon 🤫🤫

Good luck with implementing Option A - post back here if you're having any issues getting it up and running!