Skip to main content
Solved

Possible to filter out certain records in a input.recordAsync()


Kim_Trager1
Forum|alt.badge.img+21

I want to be able to pick a value which and select some some other values which shows only values that contains values that includes values from first pick.

I’ve been trying to play around with options.fields however I’m a little unsure what to put in as a fields value. I’ve tried ID’s and name values but I’m getting an error: ‘No field matching’

let filterArr = []
let filter = await input.recordAsync('Select Sender', base.getTable('Contacts').getView('Mills'))
filterArr.push('rectBqFb8f8DtgRLW')

let selectRecord = await input.recordAsync(
'Select a record', 
base.getTable(selectBase).getView(selectBaseView),
    {
    fields: filterArr,
    shouldAllowCreatingRecord: false
}
)

what do I need to pass as fields value?

Best answer by JonathanBowen

Hi @Kim_Trager1 - Not sure if I totally get your setup, but this might help. My base has two tables - countries and cities. Country is a linked record in cities:

I then have this script:

let countriesTbl = base.getTable('Countries');
let citiesTbl = base.getTable('Cities');


// pick a country
let country = await input.recordAsync('Pick a country', countriesTbl);
// if there is a country
if (country) {
    // show the chosen country
    output.text(`You picked ${country.name}`)
    let chosenCountry = country.name;
    // query the cities table
    let citiesQuery = await citiesTbl.selectRecordsAsync();
    // filter the cities records so that only those matched to the chosen country are returned
    let cityPicks = citiesQuery.records.filter(city => city.getCellValueAsString('Country') == chosenCountry)
    // now pick a city based on the filtered set of cities
    let cityPick = await input.recordAsync('Pick a city', cityPicks);
    if(cityPick) {
        output.text(`You picked ${cityPick.name}`);
    }
}

So, I’m choosing a country, then filtering the cities based on the selected country. The result (the set of filtered cities) is passed to the second record selector and only displays the appropriate cities.

Does that work for what you’re trying to do?

View original
Did this topic help you find an answer to your question?

2 replies

JonathanBowen
Forum|alt.badge.img+18
  • Inspiring
  • 1110 replies
  • Answer
  • July 23, 2020

Hi @Kim_Trager1 - Not sure if I totally get your setup, but this might help. My base has two tables - countries and cities. Country is a linked record in cities:

I then have this script:

let countriesTbl = base.getTable('Countries');
let citiesTbl = base.getTable('Cities');


// pick a country
let country = await input.recordAsync('Pick a country', countriesTbl);
// if there is a country
if (country) {
    // show the chosen country
    output.text(`You picked ${country.name}`)
    let chosenCountry = country.name;
    // query the cities table
    let citiesQuery = await citiesTbl.selectRecordsAsync();
    // filter the cities records so that only those matched to the chosen country are returned
    let cityPicks = citiesQuery.records.filter(city => city.getCellValueAsString('Country') == chosenCountry)
    // now pick a city based on the filtered set of cities
    let cityPick = await input.recordAsync('Pick a city', cityPicks);
    if(cityPick) {
        output.text(`You picked ${cityPick.name}`);
    }
}

So, I’m choosing a country, then filtering the cities based on the selected country. The result (the set of filtered cities) is passed to the second record selector and only displays the appropriate cities.

Does that work for what you’re trying to do?


Kim_Trager1
Forum|alt.badge.img+21
  • Author
  • Inspiring
  • 157 replies
  • July 24, 2020
JonathanBowen wrote:

Hi @Kim_Trager1 - Not sure if I totally get your setup, but this might help. My base has two tables - countries and cities. Country is a linked record in cities:

I then have this script:

let countriesTbl = base.getTable('Countries');
let citiesTbl = base.getTable('Cities');


// pick a country
let country = await input.recordAsync('Pick a country', countriesTbl);
// if there is a country
if (country) {
    // show the chosen country
    output.text(`You picked ${country.name}`)
    let chosenCountry = country.name;
    // query the cities table
    let citiesQuery = await citiesTbl.selectRecordsAsync();
    // filter the cities records so that only those matched to the chosen country are returned
    let cityPicks = citiesQuery.records.filter(city => city.getCellValueAsString('Country') == chosenCountry)
    // now pick a city based on the filtered set of cities
    let cityPick = await input.recordAsync('Pick a city', cityPicks);
    if(cityPick) {
        output.text(`You picked ${cityPick.name}`);
    }
}

So, I’m choosing a country, then filtering the cities based on the selected country. The result (the set of filtered cities) is passed to the second record selector and only displays the appropriate cities.

Does that work for what you’re trying to do?


Thats exactly it. Thank you


Reply