Help

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

Topic Labels: Scripting extentions
Solved
Jump to Solution
4195 2
cancel
Showing results for 
Search instead for 
Did you mean: 

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?

1 Solution

Accepted Solutions
JonathanBowen
13 - Mars
13 - Mars

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:

Screenshot 2020-07-23 at 11.58.02

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?

See Solution in Thread

2 Replies 2
JonathanBowen
13 - Mars
13 - Mars

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:

Screenshot 2020-07-23 at 11.58.02

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