Does anyone know how to schedule a task to run aft...
# suitescript
j
Does anyone know how to schedule a task to run after a delay, for example after 5 minutes? The reason is we have a N/task call to Scheduled Script that creates a sales order and then emails a PDF of that transaction. However, after the sales order is saved, we have a separate process that kicks off generation of a PDF that is included in the Advanced PDF/HTML template. That other PDF takes a couple minutes to be created, so if we try to email the transaction before that, it will fail as the template won’t be able to find the file to include.
a
Copy code
let missingPdf= true;
while (missingPdf){
   //look for the pdf
   if (pdfIsFound) {
       missingPDF = false;
   }
}
// continue with the rest of your code to send the email
c
NetSuite doesn’t really give you a “wait 5 minutes then run” option. Closest workaround is chaining scripts, so have your first scheduled script queue another via N/task once the file’s confirmed, or use a Map/Reduce with a scheduled deployment gap. Some folks hack it by scheduling the follow-up script on a 15-min interval and letting it pick up when the file’s ready, but there’s no built-in delay timer.
j
@Anthony OConnor I cannot just not send the PDF …. it always has to be sent (even if there is a delay to send)
a
right... you'll be stuck in the while loop looking for the PDF until you find it