Skip to main content

Hi, I have written a function that fetches the table value based on the table name and primary field


number = Uf79266972d007f2a3886bf73676860

async function sendContent(number, studentTable, contact) {
const records_Student = await base(`${studentTable}`).select({
filterByFormula: `${contact} = '${number}'`,
view: "Grid view",
maxRecords: 1

}).all();
var td = await totalDays(number, studentTable, contact)

records_Student.forEach(async function (record) {
studentName = record.get("Name")
console.log("Name = ", name)

})
}
sendContent(number, "Students", "UserID")

It gives the following error


AirtableError {
error: 'INVALID_FILTER_BY_FORMULA',
message: 'The formula for filtering records is invalid: Unknown field names: uf79266972d007f2a3886bf73676860',
statusCode: 422
}


But,

If I pass number as 50373. and call

sendContent(number, "Students-2", "ChatID")



It retrieves the name successfully.


Any idea what is causing this issue? the function works for one table but not for the other table where the primary field is a Single text


Here’s your problem. There are both letters and numbers in that ID, so it must be created as a string. You’re also missing either let or const in front of the variable definition. I recommend this instead:


const number = "Uf79266972d007f2a3886bf73676860"

Your other example works because it’s a true number and the value for which you’re searching is also a number (even though you’re wrapping it as a string in your filterByFormula formula, Airtable apparently considers them to be equivalent).



Here’s your problem. There are both letters and numbers in that ID, so it must be created as a string. You’re also missing either let or const in front of the variable definition. I recommend this instead:


const number = "Uf79266972d007f2a3886bf73676860"

Your other example works because it’s a true number and the value for which you’re searching is also a number (even though you’re wrapping it as a string in your filterByFormula formula, Airtable apparently considers them to be equivalent).


Hi, Thak you for your reply, I tried your solution also checked the type. It is string but still I am facing the same issue


Hi, Thak you for your reply, I tried your solution also checked the type. It is string but still I am facing the same issue


Are you getting the same error message, or is it different? The more details that you can share about what is/isn’t happening, the easier it will be for us to help.


Reply