Snippet to create a delay in a server side script

Snippet to create a delay in a server side script

The motivation behind the creation of this function stems from the absence of a built-in setTimeout functionality in the server-side environment of Netsuite. Although I personally had not encountered the necessity for such a function, I recognized the potential value it could hold for others facing similar circumstances.

It is essential to note that the provided code relies on a busy-wait mechanism, which is widely acknowledged as an antipattern and discouraged for use. This approach involves a loop that continuously checks the system clock until the specified duration elapses. While it serves as a makeshift alternative, it is important to exercise caution and consider alternative solutions whenever possible.

For your convenience, the function is provided below:

 

And then call it like this:

Beware of execution time limits when running this code. Always test first.

By incorporating this function into your code, you can simulate a delayed execution of a specified function after a given time period. However, it is advisable to explore more efficient and reliable alternatives for handling time-based operations in Netsuite’s server-side environment.

  • Dilip DiLee

    Hi adolfo

    i tried the following code
    /**
    * @NApiVersion 2.x
    * @NModuleScope Public
    * @NScriptType ClientScript
    */
    define([], runClientscript);

    function runClientscript() {
    function pageInit(context) {
    $(‘body’).innerHTML = ‘JQUERY FUNCTION WORKED’;

    return;
    }

    var returnObj = {};
    returnObj.pageInit = pageInit;
    return returnObj;
    }

    Deployed : Customer

    i didn’t find any difference.
    i dont have much idea on JQUERY trying to learn it .
    can u add some additional line of code to it so that i can see in log or alert.

    Thank you

    • Make sure the script is set to released and you are included in the list of users who can run the script. Also make sure you are on edit mode when viewing the record as clientscript only runs on edit mode.

      • Dilip DiLee

        okay Thank you