Nov 03, 2023 05:40 AM
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.
Solved! Go to Solution.
Nov 03, 2023 05:40 PM - edited Nov 03, 2023 05:41 PM
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!`)
Nov 03, 2023 08:37 AM
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!
Nov 03, 2023 05:40 PM - edited Nov 03, 2023 05:41 PM
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!`)
Nov 06, 2023 12:50 AM
@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 😄
Nov 06, 2023 12:59 AM
@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
Nov 06, 2023 06:08 AM
@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!