How To Overcome Script Execution Time Exceeded Error in Schedule script 2.0?

The disadvantage of scheduled suitescript 2.0 is that yield script functionality which is there in 1.0 has been taken away. Yield script had a great advantage of being able to resume the script from the point it stopped when time or usage limit exceeded.

As netsuite solution provider we provide a Workaround in schedule script 2.0 to overcome time exceeded error is to monitor the time taken to process the script. inIf it reaches near the time limit of 3600s after which script errors out, schedule script can be called again by netsuite customization passing the point at which it needs to resume. For eg: if you are processing 100k records and script is able to process only 50k after 55 mins, then script can be rescheduled by passing the internalid of record from which script needs to process. This internalid is passed in the script parameter.

Example code:

var startTime = new Date().getTime();

for(var i=0;i<search.length;i++)

{

var endTime = new Date().getTime();
var timeElapsed = (endTime*0.001) - (startTime*0.001);
if (timeElapsed > 3300)// more than 55 mins
                {
var scheduledScriptTask = task.create({ 
                                                                            taskType: task.TaskType.SCHEDULED_SCRIPT,                                                                                  scriptId: runtime.getCurrentScript().id, 
                                                                           params: {custscript_resume_point: internalid}
                                                                             });                                                                            
}

                 //logic to process records
}

contact us at:
Email : info@smilingcoders.com

Comments

  1. We are NetSuite Solution Provider with vast experience in NetSuite Implementation, netsuite customization including netsuite training & netsuite integration.
    NetSuite Solution Provider
    NetSuite Training
    NetSuite Implementation
    NetSuite Customization
    NetSuite Integration

    ReplyDelete

Post a Comment

Popular posts from this blog

Work Around the 1000 Row Limit Returned by Saved Searches in Netsuite

Understand Core Technology behind SuiteScript 2.0

HOW TO SET SUBLIST SUB RECORD VALUES IN SUITE SCRIPT 1.0 AND 2.0