So I have a (scheduled) suitescript that is trying...
# suitescript
s
So I have a (scheduled) suitescript that is trying to submit a scheduled task multiple times, once for each of a handful of items, but failing because after submitting it the first time, the task is still running when the script tries to submit it the second time. I was under the impression that task.submit would place it in the queue rather than failing, is there a way to have that functionality, or will I have to change my script so that it only submits the task once and the task handles all of the items in one run?
b
Share the code
Be prepared to receive the standard response of use map/reduce script instead
s
yeah I'm prepping to change to m/r scripts but that isn't happening this cycle
There isn't much code to be shared, the basics are
Copy code
searchIds.forEach(function(searchID) {
    var scriptTask = task.create({
                	taskType: task.TaskType.SCHEDULED_SCRIPT,
                	scriptId: 'customscript_sendsearch',
                	deploymentId: 'customdeploy_sendsearch',
                	params: { custscript__fileid: fileId }
                });

var searchTask = task.create({
	                	taskType: task.TaskType.SEARCH
	                });
	                searchTask.savedSearchId = searchId;
	                searchTask.fileId = fileId;
	                searchTask.addInboundDependency(scriptTask);
	                var taskId = searchTask.submit();
}
then in my sendsearch scheduled script, I take in the fileId parameter and work with it
j
Each script deployment can only be "in use" (queued or running) once at a time. In other words, you need as many deployments as you will have queued / running at the same time.
Create many deployments, and when you create the task, do not specify the
deploymentId
. NetSuite will select the first available deployment (not currently queued or running).
s
hm yea i thought that might be the case. Thanks
I'll try that
d
would that be the same case for m/r script too? would you need multiple deployments of a m/r script?
j
He is using multiple deployments because he is splitting up his input set to fit within the governance of a single scheduled script. A mapreduce script would not have the same governance limitation and would not need multiple deployments to cover the same input set. You would still need multiple deployments for a mapreduce script for more than one instance of the same script to run or be queued at the same time.
d
thanks, that's what i was looking for