Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Apr 12, 2021 06:22 AM
Hi, I’ve been working on a Next.js app with Airtable.
I’m trying to retrieve a single record by specifying the field (not reocrd ID provided by Airtabe).
I refered to the document below, but it only mentions the way of doing it by the record ID.
The code below is working fine, but I’d like to get a record by the specified column (eg. where “user_id” = 987813 ).
//export const getServerSideProps = async (context) => {
export async function getServerSideProps(context) {
let todos = await table.find('rec1PDbe0ww22feo3');
return {
props: {
initialTodos: getMinifiedRecord(todos),
},
};
}
Thanks,
Apr 12, 2021 07:05 AM
To get a specific record based on field values you need to get records for the table with filterByFormula
. You will then get an array of only the records that match that condition.
Apr 12, 2021 08:14 AM
Thanks for the reply.
Now I found the way to do it with select method, do you know if they have it with find method?
let todos = await table.select({maxRecords: 1,filterByFormula: "NOT({email} = '')"}).firstPage();