4

I have a schedule script which does some calculation and update custom header field on a Sales Orders, which runs every 30 mins.

With the increase number of order's in Netsuite, I started receiving error saying "An unexpected error has occurred"

Execution Time: 677.15s Script Usage: 75 Error:SSS_INSTRUCTION_COUNT_EXCEEDED" Script Execution Instruction Count Exceeded. Stack Trace: scheduled

Please help me to get rid of this error.

p.s: no suite answer is available for the mentioned problem.

Vijay Joshi
  • 90
  • 1
  • 6

4 Answers4

6

There is no proper documentation in NetSuite which tells the number of script lines that are allowed. As @rockstar said

NetSuite has put internal mechanisms in place to detect “runaway scripts” that include infinite loops

I faced the same error, even though there wasn't any infinite loop.

The first approach you should take is try optimizing your scripts by reducing number of loops or unnecessary script statements.

If that isn't possible or still doesn't help, you can probably yield your script after processing certain amount of data to reset the usage of script statements usage.

prasun
  • 7,073
  • 9
  • 41
  • 59
  • Thanks for the reply but yield creates a new scheduled script with a governance reset and if you notice my Script Usage: 75 . So I am running out my Script Usage? – Vijay Joshi Feb 19 '16 at 07:47
  • yield schedules a new instance and resumes from where it yielded. you aren't running out of script usage points. – prasun Feb 19 '16 at 08:04
  • @prasun you may want to look at `SuiteScript Governance` and `Governance on Script Logging` in NS help center. However you'e right on the context of yielding or re-scheduling a script but it is always recommend to finetune and optimize your code. Later is the land of last resort. – Rockstar Feb 19 '16 at 15:08
5

NetSuite has put internal mechanisms in place to detect “runaway scripts” that include infinite loops. Once caught, these scripts will be terminated and an SSS_INSTRUCTION_COUNT_EXCEEDED error message is thrown. Should you receive this error, NetSuite recommends that you examine the for loops in your script to ensure that they contain either a terminating condition or a condition that can be met.

You also may want to consider the below points

NetSuite governs the use of nlapiLogExecution(type, title, details)

The governance model is meant to safeguard against unreasonably excessive logging, which can negatively affect performance for other NetSuite customers sharing the same database. The governance model is not meant to impact companies (or scripts) that are using nlapiLogExecution() appropriately.

The governance model is as follows:

Within a 60 minute time period, a company is allowed to make up to 100,000 calls to nlapiLogExecution() across all of their scripts.

If within a 60 minute time period NetSuite detects a given script is excessively logging (and pushing a company close to the 100,000 nlapiLogExecution() call limit), NetSuite will change the offending script's log level to the next level higher. The offending script will continue its execution, however, its log level will go from Debug to Audit, or Audit to Error, or Error to Emergency, depending on the script.

The capacity for script execution logs is shared by customers on the same database. For further protection against excessive logging, script execution logs are governed by a total storage limit on each instance of the NetSuite database. On each NetSuite server, if the database table that stores logs reaches this limit, all logs (across all customers on that server) are purged. For this reason, NetSuite recommends that you store information using custom records.

Example

Company ABC has 10 scripts running during a 60 minute period. If one out of the 10 scripts calls

 nlapiLogExecution('DEBUG', 'My log', x.getID()) 

70,000 times within only a 20 minute time period, NetSuite will raise the script's log level.

The change to the log level will appear in the Log Level field on the script's Script Deployment page (see figure). In the figure below, if the offending script's Log Level was originally set to Debug, NetSuite will increase the log level to Audit. This means the line of code that reads

nlapiLogExecution('DEBUG', 'My log', x.getID()) 

will continue to execute, however nothing will be logged, as the log level for the script has been raised to Audit.

Script Owners Are Notified

If NetSuite detects that one script is logging excessively, the owner of the script is notified. The script owner is alerted that the script is the primary contributor to his or her company possibly exceeding the 100,000 logging threshold (for a given 60 minute time period).

NetSuite sends notifications through email and adds a log entry to the script's Execution Log. Both the email and the NetSuite-generated log alerts script owners that a script's Log Level has been increased.

Reference : Netsuite Help Center [ Governance on Script Logging ]

Rockstar
  • 2,228
  • 3
  • 20
  • 39
1

I usually get this error if I have some logic in a loop that takes a long time to finish. Another common cause for this are infinite loops.

Rusty Shackles
  • 2,802
  • 10
  • 11
0

You could also easily convert this into a MAP_REDUCE which will allow for this script to run without having to worry about usage units or instructional units as its all queued and designed for bulk processing. The account will only scale more so I would resort to this as the same parameters for execution can be configured the same you have for the scheduled script or use that same script to use N/task to call the MAP_REDUCE script every 30min after you refactored its logic into the MAP_REDUCE. The only thing when you're tasking this script has logic to ensure it is completed before it runs again. Then you could build some reporting on this in the summary of the MAP_REDUCE which is fun and cool!

HeavenlyEntity
  • 153
  • 2
  • 5