Our company has a service department with customers that receive service on a regular schedule, different customers have different schedules. I have a scheduled script that uses a saved search to determine all of our customers that have work due next month, it then creates a sales order for each customer.
Luckily our company is growing, and as such the number of monthly service customers is going up and up! Which is great, except when this scheduled script reaches it's 10,000 governance unit limit!
I decided to try and use nlapiYieldScript when the usage limit is being approached, so that it can continue running and create all of our sales orders.
var context = nlapiGetContext(); for (i in arrSearchResults) { [INDENT]var searchResult = arrSearchResults[i]; var arrcheckinColumns = searchResult.getAllColumns(); var stCustID = searchResult.getValue(arrcheckinColumns[0]); var stDueDate = searchResult.getValue(arrcheckinColumns[1]); var recNewOrder = nlapiCreateRecord('salesorder'); recNewOrder.setFieldValue('customform', 100); recNewOrder.setFieldValue('entity', stCustID); recNewOrder.setFieldValue('trandate', stDueDate); try { var NewSOid = nlapiSubmitRecord(recNewOrder, true); } catch(err) { nlapiLogExecution('error','Error!',err.message); nlapiLogExecution('error','Error!', recNewOrder.getFieldValue('entity')); } if( context.getRemainingUsage() < 9500) { var state = nlapiYieldScript(); if( state.status == 'FAILURE') { nlapiLogExecution("ERROR","Failed to yield script, exiting: Reason = "+state.reason + " / Size = "+ state.size); throw "Failed to yield script"; } else if ( state.status == 'RESUME' ) { nlapiLogExecution("AUDIT", "Resuming script because of " + state.reason+". Size = "+ state.size); } // state.status will never be SUCCESS because a success would imply a yield has occurred. The equivalent response would be yield } [/INDENT] } (This is a simplified version of my code, there is a lot more going on. If something else is causing the nlobjError, any ideas on how to find/fix it?)My problem is this:While looping over customers I create a new sales order called "recNewOrder" I then call nlapiSubmitRecord and catch any errors. If nlapiSubmitRecord encounters an error because a customer is on credit hold (for example) then the next time nlapiYeildScript is called, I get an error. Any ideas on how to get a successful yield after I get an errror? This is what my execution log looks like:View System JS_EXCEPTION Failed to yield script 8/27/2012 12:37 pm Printz, Sean E View Error Failed to yield script, exiting: Reason = SS_DISALLOWED_OBJECT_REFERENCE / Size = -1 / Information = nlobjError 8/27/2012 12:37 pm Printz, Sean E RemoveView Error NewSOid! 226581 8/27/2012 12:37 pm Printz, Sean E RemoveView Error Error! 31060 8/27/2012 12:37 pm Printz, Sean E RemoveView Error Error! Customer balance exceeds credit limit 8/27/2012 12:37 pm Printz, Sean E RemoveView Audit Resuming script because of SS_NLAPIYIELDSCRIPT. Size = 764585 8/27/2012 12:37 pm Printz, Sean E RemoveView System nlapiYieldScript YIELD SUCCESSFULL WITH SIZE =764585 8/27/2012 12:37 pm Printz, Sean E View Audit Resuming script because of SS_NLAPIYIELDSCRIPT. Size = 608823 8/27/2012 12:36 pm Printz, Sean E RemoveView System nlapiYieldScript YIELD SUCCESSFULL WITH SIZE =608823 8/27/2012 12:36 pm Printz, Sean E View Audit Resuming script because of SS_NLAPIYIELDSCRIPT. Size = 605362 8/27/2012 12:36 pm Printz, Sean E RemoveView System nlapiYieldScript YIELD SUCCESSFULL WITH SIZE =605362 8/27/2012 12:36 pm Printz, Sean E