I have a scheduled script that I will have run every day to update four hidden fields on a project record. The script is pretty in-depth, so for the sake of ease and length of this post I'll try and hit the important points.
My function starts and I call a saved search in the system. It returns 700+ projects. I start a "for loop" to iterate through each project to determine if all the additional steps/functions need to take place. My script was failing due to me using hitting the script usage limitations, so I added the use of nlapiYieldScript & nlapiSetRecoveryPoint. I found all of this on SuiteAnswers ID # 10279.
The Yielding and Recovery seem to be working, but only 2 or 3 times. Whenever the script yields, I get this message in my execution log of the script: " YIELD SUCCESSFULL WITH SIZE =902881". The size is about the same each time I get a failure on the scheduled script status page. The bad part is I do not have any additional info as to why it actually failed. Below is snippets of my script to help diagnose what is going on here.
for (var i = 0; i < searchResults.length; i++) { //current search results length is about 755 if( (i % 50) == 0 ) setRecoveryPoint(); //every 50 projects, we want to set a recovery point so that, in case of an unexpected server failure, we resume from the current "i" index instead of 0 checkGovernance(); ... < I do several things here to get the values for the hidden fields and populate them > } function setRecoveryPoint() { var state = nlapiSetRecoveryPoint(); //100 point governance if(state.status == 'SUCCESS' ) return; //we successfully create a new recovery point if(state.status == 'RESUME' ) //a recovery point was previously set, we are resuming due to some unforeseen error { nlapiLogExecution("ERROR", "Resuming script because of " + state.reason+". Size = "+ state.size +". Information = " +state.information); handleScriptRecovery(); } else if (state.status == 'FAILURE' ) //we failed to create a new recovery point { nlapiLogExecution("ERROR","Failed to create recovery point. Reason = "+state.reason + " / Size = "+ state.size +" / Information = " +state.information); handleRecoveryFailure(state); } } function checkGovernance() { var context = nlapiGetContext(); if(context.getRemainingUsage() < 250 ) { var state = nlapiYieldScript(); if(state.status == 'FAILURE') { nlapiLogExecution("ERROR","Failed to yield script, exiting: Reason = "+state.reason + " / Size = "+ state.size +" / Information = " +state.information); throw "Failed to yield script"; } else if (state.status == 'RESUME' ) { nlapiLogExecution("AUDIT", "Resuming script because of " + state.reason+". Size = "+ state.size +". Information = " +state.information); } // state.status will never be SUCCESS because a success would imply a yield has occurred. The equivalent response would be yield } } function handleRecoverFailure(failure) { if( failure.reason == 'SS_MAJOR_RELEASE' ) throw "Major Update of NetSuite in progress, shutting down all processes"; if( failure.reason == 'SS_CANCELLED' ) throw "Script Cancelled due to UI interaction"; if( failure.reason == 'SS_EXCESSIVE_MEMORY_FOOTPRINT' ) //avoid infinite loop { //cleanUpMemory(); setRecoveryPoint(); } if( failure.reason == 'SS_DISALLOWED_OBJECT_REFERENCE' ) throw "Could not set recovery point because of a reference to a non-recoverable object: "+ failure.information; } //function cleanUpMemory(){//...set references to null, dump values seen in maps, etc}I commented out the "cleanUpMemory" function because I am not really sure what to do in that function. My thoughts are that my size is too big and so the script fails, but when I called NS support about what the "size" meant in the log, they were not sure... they would have to take the issue "offline" and get back with me.If anyone can quickly tell me how to clean up memory and size I would greatly appreciate it.Thanks!