Browsed by
Tag: netsuite

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.

SuiteScript 2.0 Dialog Prompt + On SaveRecord

SuiteScript 2.0 Dialog Prompt + On SaveRecord

One of the new modules in Suitescript 2.0 is the “N/ui/dialog” module but unfortunately it doesn’t include a prompt method. I did some digging and found that the dialog module uses Sencha Ext JS. Since Ext JS doesn’t require the dialog module it can run on both SS 1.0 and 2.0!

Here’s how they look like side by side:

Native JS

jsprompt

Ext JS

extjsprompt

Note: This is a hack.

Here’s the code sample on how to achieve this (Works on both SS 1.0 and SS 2.0):


Additionally, thanks to this post from Abaci I was able to run this code right before the record is saved, which can be very useful to set the value of a field right before saving.

Here’s the code sample running on SaveRecord in SS 2.0:

I hope that was useful for you. Don’t forget to leave a comment if you have any questions!

Getting Item Earliest Available Date Programatically

Getting Item Earliest Available Date Programatically

I was browsing through the Netsuite user group and I stumbled upon this interesting question:

I have a client that wants to automate the process of checking/calculating the ‘Earliest Available Date’ from the ‘Check Item Availability’ feature on the item level of a sales order. I know that this calculation is done using the ATP lead time, but I am not sure how to initiate this calculation via SuiteScript or Saved Search. I have shown this issue to NetSuite support and they told me that it is not currently possible to access the “Earliest Available Date” by either Saved Search or API. It literally requires someone to click the “Check Item Availability” which loads the popup dialog and shows the date. My client would obviously like to avoid having to drill into every sales order and check this date.
 
Does anyone know of a way to display the ‘Earliest available date’ via Saved Search or API? Or many another way to calculate it via some other ATP lead time calculation.

I was able to reverse engineer the process that Netsuite uses to calculate the “Earliest Available date” and I came up with a solution that works within the browser console. The solution loads the popup in the back, parses the HTML and gets the data. This may help you get started on designing a more robust solution.

Here’s a sample output:

Here’s the code ready to run in the browser console:

Note: Since this is running in the browser you might need to play around with the script to get over 100 items at a time as the governance would run out. Alternatively you could use an Ajax call instead of nlapiRequestURL.