SetTimeOut in SuiteScript SSS_INSTRUCTION_COUNT_EXCEEDED

When using the SetTimeOut or Sleep with more than 4 or 5 seconds in the SuiteScript getting the error SSS_INSTRUCTION_COUNT_EXCEEDED

Solution:

sleep(1000);           //milisecond 1000 = 1second
function sleep(milliseconds) {‌
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {‌
     if ((new Date().getTime() - start) > milliseconds) {‌
	 break;
     }
  }
}

The script increases the instruction count and if it is set to too high then the users will get an SSS_INSTRUCTION_COUNT_EXCEEDED error. It is recommended to stop the script just for 1 or 2 seconds. Based on the testing the error above comes after 4 or 5 seconds.

NetSuite enforces a limit of instructions for every single execution of a server script. In most cases, the error is thrown by loops with a large number of iterations or a large number of distinct statements for each iteration. The error may also be caused by a script operating on a single record with a large number of line items, with multiple operations on each line.

To resolve the issue, it is strongly advised to optimize the script and improve certain lines of code that can possibly form a bottleneck and avoid long-running scripts.

Leave a comment

Your email address will not be published. Required fields are marked *