How to use return outside of select method

Topic Labels: Formulas Integrations
219 1
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

Hello, I am using the Airtable API in javascript. Currently I am using the select method based on the documentation, and I am trying to make use of the returned data outside of the method.

For example this is my code:



    view: 'Grid view',
    filterByFormula: `{FUS} = "F002"`
}).firstPage(function (err, records) {
    if (err) { console.error(err); return; }
    records.forEach(function (record) {
        PAISearch = record.get("PAISearch");




When I try to make use of the PAISearch variable that gets declared in the return of the select method, I can't get it to be accessible under the Global scope.

I would like some advice on how to use the select method to store data into global variables for use in other functions. This works great if I just want to log to console inside of the function, but I need to make use of them elsewhere.

I understand this is probably some basic JS fundamentals, as I am still learning. Thanks!

1 Reply 1
5 - Automation Enthusiast
5 - Automation Enthusiast

base('TestData').select() method is asynchronous, meaning that it doesn't pause the execution of the rest of the script while it's waiting for a response. The console.log(PAISearch) line executes before the callback function provided to .firstPage() has a chance to assign a value to PAISearch. Hence, PAISearch is undefined when trying to log it to the console.

You can cehck the JS docs here: