Search code examples
netsuitesuitescript2.0

Netsuite USAGE_LIMIT_EXCEEDED error on suitelet


I have created a suitelet script in which the line items in assembly build are set in the suitelet multiplied by quantity. i.e. if there is quantity 2 then two lines will be setting in suitelet for that item. suitelet opens by clicking save.

The problem is if there are more items in the assembly build then suitelet wont open and throws the error USAGE_LIMIT_EXCEEDED.

I tried to reduce the script code but it didnt help

var b=0;var nItemLinesCount = objRecord.getLineCount({ sublistId: 'component' }); for(var i=0; i<nItemLinesCount; i++)                                          
{

  if(Qty > 0)
  {
    for(j=0; j<Qty; j++)
    {
      sublist.setSublistValue({
      id : 'custpage_item',
      line : b,
      value : nItem
     });
       sublist.setSublistValue({
      id : 'custpage_qty',
      line : b,
      value : '1'
      }); b++;
    }
  }                                                                         
}

Solution

  • Each SuiteScript has a "usage limit" (sometimes called a governance unit).

    The way to work around this is to check much usage is left using nlapiGetContext().getRemainingUsage() and if the number is lower than what you'll expect to use in the next loop in your script, reschedule the script to run again later.

    You'll need to design your script deterministically. You need to be able to run the script multiple times without it creating any sort of duplicate data or results. If you design your script in this fashion, then rescheduling the SuiteScript to run when usage is low won't create any unintended side effect.

    Here's an example:

    https://gist.github.com/iloveitaly/eb3fffa67c5ea08010d3de6e552f84d3

    Specifically, check out the isScriptUsageRemaining and rescheduleScript functions.