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
}
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
}
We are NetSuite Solution Provider with vast experience in NetSuite Implementation, netsuite customization including netsuite training & netsuite integration.
ReplyDeleteNetSuite Solution Provider
NetSuite Training
NetSuite Implementation
NetSuite Customization
NetSuite Integration