Nov 13, 2020 07:50 AM
Hi Everyone!
I’m trying to set a 5-10 seconds delay for an automation.
I’ve checked this post :
https://community.airtable.com/t/i-need-a-delay-method-settimeout-is-undefined-not-found-window/2812...
And I’ve tried the following script:
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
await timeout(50000)//waits 5 seconds
The editor gives an error and my automation can’t complete.
Do you have any clue of how I can (A) fix this issue or (B) set a delay in a different way ?
Regards,
Nov 13, 2020 08:05 AM
Is a longer delay okay? If so, check out this support article.
Nov 13, 2020 08:13 AM
Overtly blocking a non-blocking architecture is generally a risky idea; it often leads to brittle and unexpected outcomes.
It’s always good to explain why you need a delay because there may be different pathways to achieve the automated process without a delay.
Nov 13, 2020 08:20 AM
You’re right, here is my full problem.
I’m using an Airtable Web Clipper to get a screenshot
Then I’m using one automation (on the new record created) to use the screenshot as an attachment to a Twitter message.
The problem is that the screenshot takes a few seconds to completely download into the new record. Meanwhile, the automation is already starting and finally, the tweet isn’t generated because Airtable considers that there’s no image in the field.
Introducing a short delay, would allow me to bypass the initial problem I have.
Nov 13, 2020 08:27 AM
Perhaps you could force the web clipper step to perform one additional step - set a field as “Step One Complete” and then force the next step as a dependency on the final step of the previous process.
Another idea - since you are adept with script, why not simplly use a while (!notSaved) loop or a looped try-catch process checking for the availability of the clipped image?
Dec 02, 2020 03:39 PM
Hi @Cedric_NIEUTIN,
The next solution is not the best way to do this, but it was the only way I find, as they blocked the “settimeout” function.
function delay(ms) {
var limit = new Date();
limit = limit.setMilliseconds(limit.getMilliseconds() + ms);
while ((new Date()) < limit) {
// do nothing
;
}
delay(1000); //delay 1 second
I found this on StackOverflow, so credits for that guy, but I really think it´s awful !!! haha
The thing is that this blocks entirely the script and it´s not very recommended, but in my case, I only needed a 1-second delay so it was better than building another automation workflow.
Sergio
Jul 25, 2022 02:50 PM
That help me a lot!! Thank you.
There is a missing “}” at the end, here is the right code:
function delay(ms) {
var limit = new Date();
limit = limit.setMilliseconds(limit.getMilliseconds() + ms);
while ((new Date()) < limit) {
// do nothing
;
}
}
delay(9000); //delay 9 second
Jul 26, 2022 09:58 AM
maybe a slight hack around this - i simply put in a formula field which = 1 when there is an attachment in the attachment field
and then run the automation from the formula being updated rather than the attachment field …
seems to work with a 20MB file…