How to stop script if any Usage Limit Exeed Error is coming in Netsuite?

Hi All,

When ever you deal with lot of data this is very common problem,
Netsuite provide API to get Usage.
I already wrote one post related to Usage Click Here to Read .
Please use below code to add logic for usage also

function restricUsage()
{
    var searchresult = nlapiSearchRecord('salesorder',null, null, null);
    if(searchresult)
    {
        for(var i=0; i < searchresult.length; i++)
        {
            var usage = nlapiGetContext().getRemainingUsage();
            nlapiLogExecution( 'DEBUG',  ' usage '+usage, ' i '+i);
            if(usage > 100)
            {
             //your logic here.

             }
         }
   }



}

Above code will only allow script to run in loop only if usage is greater than 30.

Thanks
Abhi

Comments