// Get the remaining usage points of the scripts
var usage = nlapiGetContext().getRemainingUsage();
// If the script's remaining usage points are bellow 1,000 ...
if (usage < 1000)
{
// ...yield the script
var state = nlapiYieldScript();
// Throw an error or log the yield results
if (state.status == 'FAILURE')
throw "Failed to yield script";
else if (state.status == 'RESUME')
nlapiLogExecution('DEBUG','Resuming script');
}