Help

Re: Add a timeout before the execution of a script

3041 1
cancel
Showing results for 
Search instead for 
Did you mean: 
JDAR
4 - Data Explorer
4 - Data Explorer
Hi everyone!
 
I wanna know how to add a timeout before this script:
 

 

const REQUEST_METHOD = "POST";

var scriptConfig = input.config();

var webhookUrl = scriptConfig.WEBHOOK_URL;
var requestConfig = {
   "method" : REQUEST_METHOD,
}

if (REQUEST_METHOD == "POST") {
   
   // Adds scriptConfig content as JSON body of request
   requestConfig.body = JSON.stringify(scriptConfig);
   requestConfig.headers = {
      "Content-Type": "application/json"
   };

   fetch(
   webhookUrl,
      requestConfig
   ).then(function(response) {
      output.set("status", 'ok')
   })

} else if (REQUEST_METHOD == "GET") {
   
   // Adds scriptConfig content as query params of request
   const qs = Object.keys(scriptConfig)
    .map(key => `${key}=${scriptConfig[key]}`)
    .join('&');
    
    // Appends queryString parameters to URL
    webhookUrl += '?' + qs
    
    fetch(
   webhookUrl,
      requestConfig
   ).then(function(response) {
      output.set("status", 'ok')
   })
} else {
}

 

The script is used to generate a webhook where I get all infos that I want.

But the script runs too fast so some formulas and stuff dont have the time to be executed.

 

So, I just want to add a timeout before it, like 30 seconds for exemple.

How could I do that?

 

Thanks in advance!

And happy new year (in advance too ahah)

 

4 Replies 4

There are many moving parts to your request. It sounds like you are running this script in an automation. 

You cannot use setTimeout() in an automation script. You can introduce a delay using other methods. (I have one in my automation script helpers in my Gumroad store.)

However, introducing a delay after the automation starts is not enough because the inputs from the triggering record will still be the partially typed info. 

I recommend reworking your automation trigger and workflow such that the user presses an Interface Button element or edits a single-select or checkbox to trigger the automation when he is done with data entry.

Basically, its an automation for the sales of the company.

When they get a contract, they fill an airtable form with all infos about the contratc and then receive it by email in PDF. So they don't have access to Airtable.

I understood that I cannot add a setTimeout to a scrpit.

So how could I process?

Since I cant modify my automation trigger.

Thank you!

Can you clarify your workflow a little? How is the automation script running too soon? Usually people say that the automation runs too soon because someone is still typing, but that isn't the case since all the information should be submitted all at once in the form.

Do you have some other automations that need to run first? Are the formulas super complicated?

Another option might be to use a scripting automation in its own action to act as a pause. Like I mentioned I have such a script in my Automation Helpers on my Gumroad store. However, the problem is that you cannot use the information from the triggering record because it will be old information. Instead you will need to do a "Find Records" action to find the original record and get the new values. Then you can use the results of the "Find Records" action to populate the values in the script that calls the webhook.

So the automation would look like this:
1. Trigger
2. Automation script that creates the pause.
3. "Find records" action that finds the triggering record.
4. Automation script that runs the webhook, with input variables set by the "Find records" action, not the trigger.

So simple... (this could be my final Airtable post) so enjoy. 😉

  1. Force automations that have specific field dependencies to flow into a view. No record should ever get to the view unless all dependencies are satisfied.
  2. Trigger the automation on the view; this will have the effect of a delay before making the record available to be processed.
  3. Remove the record from that view by setting another field which removes it from the view when the automation has successfully completed.