Help

I need a DELAY method & setTimeout() is undefined (not found Window)

Topic Labels: Scripting extentions
29465 57
cancel
Showing results for 
Search instead for 
Did you mean: 
David_Koontz
6 - Interface Innovator
6 - Interface Innovator

Hey,

I’m a newbie with JavaScript so this might be obvious …

I need a delay(ms) method to slow down the script after 5 API calls (limit 5/min.). Problem is all the JavaScript help on the intertube points to the setTimeout() method of the Window object. But it appears that Window is not instantiated inside the Airtable code block, therefore, no setTimeout() method. What’s a good workaround for this?

What might I be missing - other methods?

Thanks
David

57 Replies 57

Thanks guys!

Here it is:
curl --header “api-key: [apikeytxt]” -X GET "https://api-hazards.atcouncil.org/public/v1/wind.json?lat=[lat variable]&lng=[long variable]

Something like:

let url = '"https://api-hazards.atcouncil.org/public/v1/wind.json?lat=[lat variable]&lng=[long variable]';
let getOptions = {
    method: "get",
    headers: {
        'api-key' : 'apiKeyHere',
        'Accept'  : 'application/json',
    }
}
let postResults = await fetch(url, getOptions);

That worked! Thank you, sir!

With how much our business uses random APIs like this, I plan on sharing this and another script we recently created in the forum once they’re up and running.

Adam_Grant
4 - Data Explorer
4 - Data Explorer

This strategy still doesn’t seem to work on my end. Here’s a complete example to demonstrate. Am I doing something wrong on my end?

function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function test() {
    output.text("foo");
    await timeout(300);
    output.text("bar");
}

test();

Expected: “foo” prints, then “bar” 300ms later.
Actual: “foo” prints, “bar” never does.

You need to await the test function when you call it.

await test();

Thank you very much @openside,
I was just needing a DELAY and you’ve helped very much !

As I read the all thread coming from this one:

I would add that
window is globalThis here in the Script-Block.

Thank you and good night (GMT),

olπ

Wylan_Osorio
4 - Data Explorer
4 - Data Explorer

image

It is not working on my script. Do you guys have solution already for this?

Welcome to the Airtable community!

It looks like you are using an automation script. The scripts which have been able to use setTimeout have been scripts run in Scripting app. There are a few differences between running a script as an automation and running a script in Scripting app. The ability to use setTimeout appears to be one of these differences.

Do you know any alternative to put delay in automation script?

Why do you need a delay in your automation script? That might influence the approach. Two common approaches are reworking the trigger, or splitting the automation into two automations.