Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Script Querying specific records with a specific value with more than 100 records

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

Is it possible to select records in scripting with specific conditions? If I wanted to get all the records that have a field value of green, how would I write that query? I don’t want to just get all the records; I want specific records with more than 100 results.

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

You currently cannot specify conditions when querying records in scripting. You must get all the records and then filter the result in JavaScript.

const table = base.getTable("myTableName")
const fieldName = "color"
const queryResult = await table.selectRecordsAsync({fields: [fieldName]})
const greenRecords = queryResult.records.filter(record => (
  record.getCellValueAsString(fieldName) == "green"
))
console.log(greenRecords)

See Solution in Thread

1 Reply 1
kuovonne
18 - Pluto
18 - Pluto

You currently cannot specify conditions when querying records in scripting. You must get all the records and then filter the result in JavaScript.

const table = base.getTable("myTableName")
const fieldName = "color"
const queryResult = await table.selectRecordsAsync({fields: [fieldName]})
const greenRecords = queryResult.records.filter(record => (
  record.getCellValueAsString(fieldName) == "green"
))
console.log(greenRecords)